如何将一个事件附加到多个选择器?
例如
$("#selector1 #selector2").change(function() { //not a valid code
alert("hi");
... }
TIA
答案 0 :(得分:3)
在选择器之间使用逗号。如果您想要多个活动,则需要使用on
并指定
$("#selector1, #selector2").change(function() { //not a valid code
alert("hi");
}
答案 1 :(得分:2)
将类值设置为两个选择器
<input class="className" id="selector1"....
<input class="className" id="selector2"....
$(".className").change(function() { //not a valid code
alert("hi");
... }