如何获取被检查的“key”属性的值???
Html代码:
<input type="checkbox" class="each-tab-1" key="some1" value="456">
<input type="checkbox" class="each-tab-1" key="some1" value="789">
<input type="checkbox" class="each-tab-1" key="some2" value="890">
<input type="checkbox" class="each-tab-1" key="some2" value="901">
<input type="checkbox" class="each-tab-1" key="some1" value="012">
JS代码:
'click .action' : function(event, template){
$("input[class^=each]:checked").each(function(){
console.log(this.value);
console.log(this.attr('key')); **// giving error "Uncaught TypeError: undefined is not a function"**
});
}
答案 0 :(得分:0)
用$(this)
封装底部$("input[class^=each]:checked").each(function(){
console.log(this.value);
console.log($(this).attr('key')); // giving error "Uncaught TypeError: undefined is not a function"**
});