如何获得流星中的自定义属性值?

问题描述 投票:0回答:1

如何获得被检查的“键”属性的值?

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"**
    });
}
javascript meteor checkbox dom-events
1个回答
0
投票

只需用$(this)包装底部的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"**
});
© www.soinside.com 2019 - 2024. All rights reserved.