我有几个选择框,我想知道触发了哪个选择框。
HTML代码:
<form id="property-filters" method="post">
<select name="sel1">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select name="sel2">
<option value="3">3</option>
<option value="4">4</option>
</select>
</form>
J查询代码:
$(document).on('change', '#property-filters input, #property-filters select', function ()
{
//Get the name of the select box.
}
非常感谢任何帮助。提前致谢。
最佳答案
检查事件触发的 dom 对象的名称属性。
$(document).on('change', '#property-filters input, #property-filters select',function () {
if(this.name == 'sel1'){
// do the rest
}else if(this.name == 'sel2'){
// do the rest
}
})
关于javascript - 在jquery中获取选择框名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40377280/