如何获得选择元素的价值以及如何对变化采取行动? [英] How to get value of select element and how to act on change?
问题描述
jQuery中的 change()事件出现问题:
$("select[name=cmm]").change(function(){
total();
});
由于某种原因,未使用上述代码调用total函数。 html代码为:
For some reason the "total" function isn't being called with the code above. The html code is:
<select name="cmm">
<option value="none">none</option>
<option value="one">the first</option>
<option value="two">the second</option>
</select>
我指的是错误的方式或元素?或者以错误的方式调用函数?
Am i referring to the element the wrong way or something? Or calling the function the wrong way?
更新:
此处的警报功能未显示,所以我猜测改变事件永远不会被调用..
Update: The alert function here doesn't show up, so I'm guessing the change event is never called..
$(document).ready(function() {
$("select[name=cms]").change(function(){
total();
alert($("select[name=cms]").length);
});
});
(是的,我一直在使用doc-ready)
(and yes, I have been using doc-ready all the time)
推荐答案
我遇到了问题,因为我使用了一个插件来设置select元素的样式。
我的问题的解决方案(因为onchange功能不起作用)在这里:
http://code.google.com/p/lnet/issues/detail?id=41
I was having the problem because of a plugin I was using to style the select element. The solution to my problem (being that the onchange function wouldn't work) is here: http://code.google.com/p/lnet/issues/detail?id=41
这篇关于如何获得选择元素的价值以及如何对变化采取行动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!