重点是.on("input propertychange")
监听文本情况添加选中样式
$(document).on("input propertychange",'[name="desc"]',function(){
$('.v1-homework-testlist').eq($(this).data('idx')).addClass('active');//如果不为空添加选中样式
});
【jQuery】input textarea 文本变化的动态监听
实时监听Input textarea文本变化的监听事件:【但不包含通过js动态添加改变的文本事件】
HTML:
<textarea style="display: none" class="notifyDetail"></textarea>
JS:
/**
* textarea值改变事件的监听
*/
$(document).on("input propertychange",".notifyDetail",function(){
alert(123);
});
1.只需要同时绑定 oninput 和 onpropertychange 两个事件,获取input元素,并实时监听用户输入。
KaTeX parse error: Expected '}', got 'EOF' at end of input: …unction(){ if((this).val()){
console.log(“hhhhhhhh”);
}else{
console.log(“xxxxxxxx”);
}
})
但这并不完美,因为用的bind,所以当遇到追加的新input标签时,则不能监听了。
2.为了解决上面的问题,可以使用live替代
$(‘input’).live(‘input propertychange’, function()
{
//获取input 元素,并实时监听用户输入
//逻辑
})