如何绑定到 jQuery 中 textarea 的更改事件? [英] How can I bind to the change event of a textarea in jQuery?
本文介绍了如何绑定到 jQuery 中 textarea 的更改事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想捕获 是否发生任何更改.就像键入任何字符(删除、退格)或鼠标单击并粘贴或剪切.是否有可以触发所有这些事件的 jQuery 事件?
I want to capture if any changes happened to <textarea>
. Like typing any characters (deleting,backspace) or mouse click and paste or cut. Is there a jQuery event that can trigger for all those events?
我尝试过更改事件,但它仅在从组件中退出后才触发回调.
I tried change event, but it triggers the callback only after tabbing out from the component.
使用:如果 包含任何文本,我想启用按钮.
Use: I want to enable a button if a <textarea>
contains any text.
推荐答案
试试这个:
$('#textareaID').bind('input propertychange', function() {
$("#yourBtnID").hide();
if(this.value.length){
$("#yourBtnID").show();
}
});
演示
这适用于您所做的任何更改、打字、剪切、粘贴.
DEMO
That works for any changes you make, typing, cutting, pasting.
这篇关于如何绑定到 jQuery 中 textarea 的更改事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文