我似乎无法弄清楚为什么更改事件会为此select元素触发两次:
<form name="contactform">
<label for="requesttype">Request Type:</label>
<select name="requesttype" class="reqtype">
<option value="1" selected>General Comment / Request</option>
<option value="2">No Cost Services Quote</option>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)
使用此jquery代码时:
$(function() {
$(".reqtype").change(function(){
alert($(".reqtype option:selected").val());
})
});
Run Code Online (Sandbox Code Playgroud)
我仔细检查了我使用"reqtype"类的唯一地方是在select元素中.任何帮助,将不胜感激.
小智 9
有类似的问题,并尝试了我能找到的所有解决方案.对我来说唯一有效的是在变更检查之前解除绑定(上面的DevPat提到):
jQuery("#wfselect").unbind();
jQuery("#wfselect").change(function() { getWFDetail(); });Run Code Online (Sandbox Code Playgroud)