jQuery调用.change无需用户操作,但通过.val更改 [英] jquery invoke .change without user action but by .val change

查看:94
本文介绍了jQuery调用.change无需用户操作,但通过.val更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文本框的表单,该表单的值已从函数中更改.我将如何基于脚本中更改的值而不是用户单击"或手动更改值的方式创建函数?

I have a form with a text box that has its value changed from a function. How would I create a function based on the value changing from the script and not the user "clicking" or manually changing the value?

我有这个:

$(document).ready(function() {
    $('#ShippingCost').live({
        change: function() { 

alert('changed!');
        }
     });
});

但是它仅在用户手动更改时起作用.

But it only works when a user changes it manually.

推荐答案

您将需要在更新值的代码中自己调用更改:

You will need to call the change yourself in the code which updates the value:

$('#ShippingCost').val("something")
                  .change();  // this will execute the change code

通过javascript更改值不会触发事件.

Changing values through javascript does not fire events.

这篇关于jQuery调用.change无需用户操作,但通过.val更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆