首页 > 其他 > 详细

文本框改变时触发

时间:2017-03-03 01:25:09      阅读:211      评论:0      收藏:0      [点我收藏+]
<html>
<head></head>
<body>
<textarea id=‘textarea‘></textarea>
</body>
</html>
<script>
    // This example shows how to use the oninput, onpropertychange and textInput events to detect when the contents of a textarea element is changed. Both the oninput and onpropertychange events are buggy in Internet Explorer 9, they are not fired when characters are deleted only when inserted.
var textarea = document.getElementById ("textarea");

if (textarea.addEventListener) {   
    // all browsers except IE before version 9
  textarea.addEventListener ("input", OnInput, false);
  // Google Chrome and  Safari
  textarea.addEventListener ("textInput", OnTextInput, false);
  // Internet Explorer from version 9
  textarea.addEventListener ("textinput", OnTextInput, false);
}

if (textarea.attachEvent) { 
    // Internet Explorer and Opera
  textarea.attachEvent ("onpropertychange", OnPropChanged);
}

// Google Chrome, Safari and Internet Explorer from version 9
function OnTextInput (event) {
  alert ("The following text has been entered: " + event.data);
}
// Firefox, Google Chrome, Opera, Safari from version 5, Internet Explorer from version 9
function OnInput (event) {
  alert ("The new content: " + event.target.value);
}
// Internet Explorer
function OnPropChanged (event) {
    // 使用event.propertyName 过滤
  if (event.propertyName.toLowerCase () == "value") {
    alert ("The new content: " + event.srcElement.value);
  }
}

</script>

 

文本框改变时触发

原文:http://www.cnblogs.com/gaocong/p/6493191.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!