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

时间:2015-05-04 08:35:20

标签: javascript checkbox meteor javascript-events

如何获取被检查的“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"**
    });
}

1 个答案:

答案 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"**
});