当前位置: 代码迷 >> JavaScript >> juqery bind有关问题 困扰了小弟我5个小时了 在线求解
  详细解决方案

juqery bind有关问题 困扰了小弟我5个小时了 在线求解

热度:555   发布时间:2013-09-06 10:17:17.0
juqery bind问题 困扰了我5个小时了 在线求解
<body>
<input id="test" type="text" />
</body>
<script>
    $("#test").bind("propertychange",function(){  
        alert($("#test").val());
    });  
</script>
ie8下 比如输入“百度”
弹出百度 和 百度百度 2次 
为什么会弹出2次?

------解决方案--------------------
用keyup吧
    $("#test").bind("keyup",function(){  
        alert($("#test").val());
    });  
------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

<body>
<input id="test" type="text" />
</body>
<script>
    $("#test").bind("propertychange",function(){  
        alert($("#test").val());
    });  
</script>
ie8下 比如输入“百度”
弹出百度 和 百度百度 2次 
为什么会弹出2次?


建议别用这个事件, 这是ie专有的事件,其他浏览器都不工作
下面是个jquery 扩展 TextChanged 支持所有的浏览器
http://rayaspnet.blogspot.ca/2011/01/how-to-implement-textchanged-event.html



哥们 你发的这个网页打不开啊?

是吗?
看代码

plugin定义:

(function (a) {
????a.event.special.textchange = {
????????setup: function () {
????????????a(this).data("lastValue", this.contentEditable === "true" ? a(this).html() : a(this).val());
????????????a(this).bind("keyup.textchange", a.event.special.textchange.handler);
????????????a(this).bind("cut.textchange paste.textchange input.textchange", a.event.special.textchange.delayedHandler)
????????},
????????teardown: function () {
????????????a(this).unbind(".textchange")
????????},
????????handler: function () {
  相关解决方案