开发者

How to fire select value change even in a combo box programmatically?

开发者 https://www.devze.com 2023-02-22 07:03 出处:网络
I\'ve a combo box and want to select an option value. I\'m using something like: $(\"#comState_city option:eq(0)\").attr(\"value\",chk[i]);

I've a combo box and want to select an option value. I'm using something like:

$("#comState_city option:eq(0)").attr("value",chk[i]);
$("#comSt开发者_C百科ate_city option:eq(0)").attr("selected","selected");

But this isn't firing value change event. I want the onchange handler be called when I changed the value of a select element.


$('#comState_city option:eq(0)').trigger('change');


Try this one:

$("#comState_city").change(function(){
    alert($(this[this.selectedIndex]).val());
});
0

精彩评论

暂无评论...
验证码 换一张
取 消