繁体   English   中英

如何监视jquery中的只读输入? .change()方法无效,因为它仅适用于非只读输入

[英]How do you monitor a read only input in jquery? The .change() method doesnt work as it only works for non read-only inputs

如果我的HTML文件中有以下代码行:

我不能使用像这样的代码来更新contractLengthDisplay因为它是只读的:

$("#contractLengthDisplay").change(function(){
   alert(1);
});

如果输入是只读的,是否有.change()方法的替代方法? 谢谢!

使用.trigger("change")通知侦听器

 $("#contractLengthDisplay").on("change", function() { // attach listener console.log( this.value ); }); $("#contractLengthDisplay") .val("BBBBB") // change value .trigger("change"); // and notify the listener by triggering the event 
 <script src="https://code.jquery.com/jquery-3.1.0.js"></script> <input id="contractLengthDisplay" value="AAAAA" readonly> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM