[英]Change function on Javascript/jQuery
I have a textfield, and I want the field to be disabled or read only if I change text on the field. 我有一个文本字段,我希望该字段被禁用或仅当我更改该字段上的文本时才能读取。 But, before that, I can't make change function.
但是,在此之前,我无法更改功能。 I don't know why.
我不知道为什么
I have tried this code : 我已经尝试过此代码:
$("#submitOrder_cust_id_name").click(function () {
alert("Test");
});
and when I click the field it is working. 当我单击该字段时,它正在工作。
But, when I use this code 但是,当我使用这段代码时
$("#submitOrder_cust_id_name").change(function () {alert("Test");});
or this code 或此代码
$("#submitOrder_cust_id_name").on('change', function () {
alert("Test");
})
it doesn't work at all. 它根本不起作用。
Please help. 请帮忙。 Thanks.
谢谢。
jquery change event trigger only when hit enter on the text box. jQuery 更改事件触发器仅在文本框上按回车时触发。 If you want to trigger a event when you enter any character use "keypress" instead of "change"
如果要在输入任何字符时触发事件,请使用“按键”而不是“更改”
Refer this : https://www.w3schools.com/jquery/event_keypress.asp 参阅此: https : //www.w3schools.com/jquery/event_keypress.asp
use on 'change'
: 在
'change'
:
$('#submitOrder_cust_id_name').on('change', function () { alert('test'); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="submitOrder_cust_id_name" />
Try using .blur()
. 尝试使用
.blur()
。 This will be called when the input field loses focus: 当输入字段失去焦点时将调用此方法:
$('#submitOrder_cust_id_name').on('blur', function () { alert('test'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="submitOrder_cust_id_name" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.