我想触发$(文档)中下拉列表的更改事件.准备好使用jquery了.

I have a cascading dropdown for country and state in user details page. how can i set the value (which is taken from DB based on the user id) for country and state in MVC with C#.

推荐答案

I don't know that much JQuery but I've heard it allows to fire native events with this syntax.

$(document).ready(function(){

    $('#countrylist').change(function(e){
       // Your event handler
    });

    // And now fire change event when the DOM is ready
    $('#countrylist').trigger('change');
});

在调用trigger()或change()之前,必须声明更改事件处理程序,否则将不会触发它.谢谢你提到@LenielMacaferi.

更多信息here.

Jquery相关问答推荐

提交表单时运行自定义验证脚本

bootstrap - Select Select 器不能在下拉菜单中 Select

更改后如何使用 jQuery Select CSS 类

如果选中了三个sibling ,则选中一个复选框

jQuery 1.4.1 中缺少 JSON 字符串化?

在范围内设置文本

仅在 _some 字段上通过 Enter 键禁用表单提交

如何使用 jQuery 以编程方式触发对链接的点击?

找到下一个匹配的sibling 姐妹的有效,简洁的方法?

如何使用 jQuery 获取 div 的当前类?

如何正确卸载/销毁 VIDEO 元素

如何在 JQuery DataTable 中默认显示所有行

JQuery html() 与 innerHTML

使用 jQuery Select 焦点文本在 Safari 和 Chrome 中不起作用

如何检测 window.print() 完成

捕获在页面任意位置按下的 Enter 键

获取没有在css中设置高度的div的高度

jQuery .hasClass() 与 .is()

更改 url 而不使用 javascript 重定向

如何使用 jquery 更改元素类型