【发布时间】:2013-11-28 10:58:52
【问题描述】:
在我的 html 中:
<input type="checkbox" name="select">
<input type="radio" name="select">
由于某些逻辑原因,名称属性相同
在我的 JS 中
我写下面的代码:
$('input[type="checkbox"],input[type="radio"]').on("change",function(event){
console.log(event.target.nodename);
// on both cases it show "INPUT"
}
});
我如何知道我点击了复选框或单选按钮?
【问题讨论】:
-
你可以(ES6+)使用返回布尔值的Element.matches(),而不是使用JQuery。
标签: javascript html jquery forms radio-button