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

<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>

posted @ 2016-10-21 08:31  kan_kan  阅读(904)  评论(0编辑  收藏  举报