简体   繁体   English

我怎样才能让 onchange 事件对 javascript/Jquery 的文本输入框更新起作用?

[英]How can I make the onchange event work for the text input box update by the javascript/Jquery?

Does anyone know how can I make the onchange event work for the text input box update by the javascript/Jquery?有谁知道如何使 onchange 事件对 javascript/Jquery 的文本输入框更新起作用?

Example:例子:

Instead of manually key in the text into the input box, I will insert the value into the text box by using jquery as below.我将使用 jquery 将值插入到文本框中,而不是手动将文本输入到输入框中,如下所示。 Any way that the onchange event will work once the value been change in the text box by jquery?一旦jquery在文本框中更改值,onchange事件将以任何方式工作? Any way I can make it work?有什么办法可以让它工作吗?

HTML: HTML:

<table>
  <tr>
    <td>
       <input type="text" ID="test" />
    </td>
  </tr>
</table>

Javascript: Javascript:

$(".test").val("ABC");


$('.test').change(function () {
    alert('hello')
});

Trigger it:触发它:

$('.test').change(function () {
    alert('hello');
});

$(".test").val("ABC");
$('.test').trigger('change');

暂无
暂无

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

相关问题 如何在动态创建的输入上绑定onchange事件? (没有jQuery) - How can I bind onchange event on dynamically created input ? (no jquery) 使用javascript更新select onchange事件上的文本框 - update text box on select onchange event using javascript 如何使 Javascript focus() 方法在输入文本框的 onBlur 事件中起作用? - How to make Javascript focus() method work in onBlur event for input text box? javascript将变量传递给文本输入onchange事件不起作用 - javascript pass variable to text input onchange event not work 无法将活动设为“不变” <select>用JavaScript工作 - Can't make the event “onchange” on <select> work in javascript 使用jQuery在文本框上的onchange和焦点事件 - onchange and focus out event on a text box with jquery 如何将onchange上的值传递给jquery中的另一个onchange事件 - How can I pass the value on onchange to another onchange event in jquery 如何验证文本框以仅在Javascript中的onkeypress事件中限制字符的输入 - How can I validate the text-box for restricting the input for characters only in onkeypress event in Javascript 如何使用 onchange 事件更新输入值并获取 vanilla Javascript 中的值? - How do I update the input value using an onchange event and get the value in vanilla Javascript? 如何使用Jquery将此javascript向上/向下数字输入框设置? - How can I make this javascript Up/Down Numeric input box using Jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM