English 中文(简体)
jj 查询所有文本输入修改的监听
原标题:jQuery Listen For All Text Input Changes

我在一个表格中有一个输入元素, 我希望能够在值变化时提取其值。 请查看这个小问题 : < a href="http://jsfiddle. net/spryno724WBzW/1/" rel="noreferr" >http://jsfiddle. net/spryno724/WABzW/1/ 。

使用 change 事件, 当输入松开焦点时, 我能够显示文本输入的值。 但是, 当窗体被重置或 JavaScript 清除文本输入值时, 该值不会更新 。

是否有具体事件可以让我聆听? 当“ 强势”

Id like to 避免工作替代, 例如监听窗体重置的时间或按下清晰按钮的时间 < / strong> 。 这是我应用程序的简化示例, 如果我尝试这样做的话, 它会变得非常快 。

谢谢你抽出时间

最佳回答

这个问题与另一个问题完全重复。

< a href=" "https://stackoverflow.com/ questions/1847893/js-events-hooking-on-value-chang-event-on-text-inputs" >JS 事件:在文本投入上将价值变化活动挂勾

问题回答
$(document).ready(function() {
    $( input.clear ).click(function() {
        $( input.input ).val(  );
        $( p.display ).text( The value of the text input is:  );
    });

    $( input.input ).on( keyup change , function() {
       $( p.display ).text( The value of the text input is:   + $(this).val());
    });
})​

http://jsfidd.net/3tDFg/1/" rel="noreferrer" >DEMO 1

也许这个解决方案可以帮助您:

$(document).ready(function() {
    $( input.clear, input[type=reset] ).on( click , function() {
        $( input.input ).val(  ).change();
        $( p.display ).text( The value of the text input is:  );
    });

    $( input.input ).on( keyup change , function() {
        $( p.display ).text( The value of the text input is:   + $(this).val());
    });
});​

http://jsfidd.net/3tDFg/3/" rel="noreferrer" >DEMO 2

覆盖 jQuery 的 val 方法

< 强 > HTML

<强 > JS

var myInput = $( #myInput );

//this will not trigger the change event
myInput.val( v2 );

//override val method
var oldVal = myInput.val;
myInput.val = function(value){
   var returnVal = oldVal.call(this,value);
   myInput.change();
   return returnVal;
}

// this will trigger the change event
// myInput.val is overridden
myInput.val( v3 );

只有从 myInput 变量中调用 val 方法, 才能有效 。

尝试

$( #input ).live( change ,function() {         })




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!