JS改變input的value值不觸發onchange事件解決方案


$("#datetxt").on("input propertychange", function () {
     alert('變化了');
});




http://blog.csdn.net/zhbitxhd/article/details/12943091




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
<meta charset="utf-8" />     
    <title>My JSP 'testInput.jsp' starting page</title>  
      
 <meta http-equiv="pragma" content="no-cache">  
 <meta http-equiv="cache-control" content="no-cache">  
 <meta http-equiv="expires" content="0">      
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
 <meta http-equiv="description" content="This is my page">  
<script type="text/javascript">  
function addValue(){  
   document.getElementById("mytext").value='dfdsafdsfsfsdfsdfdsf';  
   init();  
}  
function addValue2(){  
    document.getElementById("mytext").value='哈哈哈哈';  
    init();  
}  
function changeValue(){  
    document.getElementById("webtest").value=document.getElementById("mytext").value;  
}  
function init(){  
   if("\v"=="v"){//IE瀏覽器  
    document.getElementById("mytext").onpropertychange=changeValue;  
   }else{ // 其他瀏覽器  
 document.getElementById("mytext").addEventListener("input",changeValue(),false);  
   }  
  }  
</script>  
  </head>  
  <body>  
    <input type="button" id="txts"  value="點擊加載值!" οnclick="addValue();"/>  
    <input type="button" id="txts2"  value="第二次改加載值!" οnclick="addValue2();"/>  
    <input type="text" name="textfield" id="mytext"/>  
    <div>您輸入的值爲:<input id="webtest"></input></div>  
  </body>  
</html>  

發佈了23 篇原創文章 · 獲贊 3 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章