当其中的值被程序更改时,我想检查一个 textarea
。
代码非常复杂,所以我宁愿使用事件监听器,也不愿寻找确切的代码行。
我是这样检查的:
$(".edit.btn.btn-default").on("click", function(){
alert($("#attribute_fabric_en").val());
$("#attribute_fabric_en").on("input propertychange",function(){
alert("test");
});
});
结果:alert($("#attribute_fabric_en").val());
打印一个空字符串,但是 textarea
稍后会被赋值通过脚本;但不会触发监听器。
至少经过测试的 Chrome 无法捕获事件
最佳答案
有一个事件,在 jQuery 中你可以使用 $('.textareaId').on('change', console.log($('#textareaId').html())
,就是这么简单!
编辑:
也许你不想使用 jQuery,click 事件用于 textarea、contentediatble div 等,而 input 事件用于表单元素,例如
textArea.addEventListener('change', function(e){ ... }, false);
\n
inputElement.addEventListener('input', function(e) { ... }, false);
关于javascript - 如何检测文本区域值何时被脚本更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33529044/