由于某种原因,该事件未被解雇
<div id="plotSelectionBar">
<span>Select What to plot</span>
<select class="plotSelector" id="firstDropdown">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<span>Select What to plot2</span>
<select class="plotSelector" id="secondDropdown">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</div>
事件句柄如下:
$('.plotSelector').change(function(e)
{ if (this.id="firstDropdown)
{
//do something
}
else {//do something}
});
我在这个上面有另一个事件句柄,它正好被解雇了。发生了什么事?
答案 0 :(得分:1)
您有语法错误,需要在仅使用元素更改事件
之后调用文档
$( document ).ready(function() {
$('.plotSelector').change(function(e){
if(this.id == "firstDropdown")
alert(1)
else
{
alert(2)
}
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="plotSelectionBar">
<span>Select What to plot</span>
<select class="plotSelector" id="firstDropdown">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<span>Select What to plot2</span>
<select class="plotSelector" id="secondDropdown">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</div>