admin管理员组文章数量:1405412
I am setting the selected value of a select list as below
$("#typeFilter").val("0");
My question is do making this, triggers $("#typeFilter").change
event?
I am setting the selected value of a select list as below
$("#typeFilter").val("0");
My question is do making this, triggers $("#typeFilter").change
event?
- 4 How about trying that out yourself and let us know too ? – gkalpak Commented May 16, 2013 at 6:21
- Have you even tried to check if it does? – Mohayemin Commented May 16, 2013 at 6:23
4 Answers
Reset to default 4No it won't trigger the change event if you want to trigger the event after setting the value use trigger
. Change event is triggered only if it is an interaction from device not with javascript.
$("#typeFilter").val("0");
$("#typeFilter").trigger('change');
Sample Demo
No, it doesn't! Unless the value is changed by user interaction, change event would not be triggered.
You can try it out yourself. Select any textbox's id. Lets say the id is "inputEmail". Try the following code:
$("#inputEmail").change(function() {
alert("changed");
});
Then try the following line of code:
$("#inputEmail").val("abc");
Notice that the alert message did not appear.
No, it doesn't trigger it as it can bee seen in this live demo
. You will need to trigger it manually after setting the value:
$("#typeFilter").change();
Nopes. It doesn't change. This is the code I used:
$(document).ready(function(){
setTimeout(function(){
$("#test").val("3");
}, 1000);
$("#test").change(function(){
alert("Changed!");
});
});
So, if you would like to trigger the change, you can use something like this:
$(document).ready(function(){
$("#test").val("3").trigger("change");
$("#test").change(function(){
alert("Changed!");
});
});
Fiddles:
http://jsfiddle/praveenscience/kLJuS/
http://jsfiddle/praveenscience/kLJuS/1/
版权声明:本文标题:javascript - Do setting selected value of a select box trigger change event of the select list? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744262893a2597803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论