使用javascript(jQuery)设置值时TextBox onchange(TextBox onchange when setting value with javascript (jQuery)) $(document).ready(function() { $('#text').live('change', function() { alert('hello'); }); $('#button').live('click', function() { $('#text').val('some text'); }); }); <div> <input type="button" id="button" value="Click Me" /> <input type="text" id="text" /> </div>

单击按钮后,如何在文本框触发器上进行change功能? 谢谢

$(document).ready(function() { $('#text').live('change', function() { alert('hello'); }); $('#button').live('click', function() { $('#text').val('some text'); }); }); <div> <input type="button" id="button" value="Click Me" /> <input type="text" id="text" /> </div>

How can I make the change function on the textbox trigger when I click the button? Thanks

最满意答案

您可以使用.change() (快捷方式)或.trigger() ,如下所示:

$('#button').live('click', function() { $('#text').val('some text').change(); });

或这个:

$('#button').live('click', function() { $('#text').val('some text').trigger('change'); });

这两种方法都可以触发您添加的任何change事件处理程序 , 您可以在此处进行测试 。

You can use .change() (the shortcut) or .trigger(), like this:

$('#button').live('click', function() { $('#text').val('some text').change(); });

Or this:

$('#button').live('click', function() { $('#text').val('some text').trigger('change'); });

Either method works to trigger any change event handlers you've added, you can test it here.

使用javascript(jQuery)设置值时TextBox onchange(TextBox onchange when setting value with javascript (jQuery)) $(document).ready(function() { $('#text').live('change', function() { alert('hello'); }); $('#button').live('click', function() { $('#text').val('some text'); }); }); <div> <input type="button" id="button" value="Click Me" /> <input type="text" id="text" /> </div>

单击按钮后,如何在文本框触发器上进行change功能? 谢谢

$(document).ready(function() { $('#text').live('change', function() { alert('hello'); }); $('#button').live('click', function() { $('#text').val('some text'); }); }); <div> <input type="button" id="button" value="Click Me" /> <input type="text" id="text" /> </div>

How can I make the change function on the textbox trigger when I click the button? Thanks

最满意答案

您可以使用.change() (快捷方式)或.trigger() ,如下所示:

$('#button').live('click', function() { $('#text').val('some text').change(); });

或这个:

$('#button').live('click', function() { $('#text').val('some text').trigger('change'); });

这两种方法都可以触发您添加的任何change事件处理程序 , 您可以在此处进行测试 。

You can use .change() (the shortcut) or .trigger(), like this:

$('#button').live('click', function() { $('#text').val('some text').change(); });

Or this:

$('#button').live('click', function() { $('#text').val('some text').trigger('change'); });

Either method works to trigger any change event handlers you've added, you can test it here.