该事件因某种原因没有触发
<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}
});
我在此上方有另一个事件手柄,该事件正好很好。发生了什么事?
您有语法错误,需要准备好调用文档,之后仅使用您的元素更改事件
$( 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>