input内容改变触发事件,兼容IE

时间:2020-12-18 14:24:49
<html>

<head>
<script type="text/javascript">
window.onload = function(){
myFunction = function(){
console.log("1");
} } </script>
</head> <body> Enter your name: <input type="text" id="fname" oninput="myFunction()" onpropertychange="myFunction()"> </body>
</html>
<html>

<head>
<script type="text/javascript">
window.onload = function(){
myFunction = function(){
console.log("1");
}
var oTest = document.getElementById('fname');
if(oTest.attachEvent){
oTest.attachEvent('onpropertychange',function(){
console.log("1");
});
}
else{
oTest.addEventListener('input',function(){
console.log("1");
}
);
} } </script>
</head> <body> Enter your name: <input type="text" id="fname"> </body>
</html>

 

<html>

<head>
<script type="text/javascript">
window.onload = function(){
    myFunction = function(){
        console.log("1");
    }

}
 
</script>
</head>

<body>

Enter your name: <input type="text" id="fname" oninput="myFunction()" onpropertychange="myFunction()">

</body>
</html>