获取多个复选框数据属性

时间:2016-01-18 18:21:45

标签: javascript jquery checkbox

如何获取多个复选框数据属性(仅选中)?

我可以获取复选框值,但不能获取数据属性:

<script type="text/javascript">
//export upc
  $('#export_upc').click(function(){
    var arr = $('.checkboxes:checked').map(function(){
        return this.value;
    }).get();
    console.log(arr);
}); 
</script>

我尝试return this.data("upc"),但这不起作用。

2 个答案:

答案 0 :(得分:1)

您是否尝试过#define ON_BIT = 0x01 char *strToBin(char c) { static char strOutput[10]; int bit; /*Shifting bits to the right, but don't want the output to be in reverse * so indexing bytes with this... */ int byte; /* Add a nul at byte 9 to terminate. */ strOutput[8] = '\0'; for (bit = 0, byte = 7; bit < 8; bit++, byte--) { /* Shifting the bits in c to the right, each time and'ing it with * 0x01 (00000001). */ if ((c >> bit) & BIT_ON) /* We know this is a 1. */ strOutput[byte] = '1'; else strOutput[byte] = '0'; } return strOutput; }

答案 1 :(得分:1)

this表示DOM元素。您应该使用jquery对象$(this)代替。

$(this).data("upc")