如何从标签数据类型=“;无线电”;


How I can get value from label data-type="radio"

如何从label data-type="radio"获取值?这是我正在使用的代码:

<label id="condition" class="btn btn-default toggle-class" data-toggle="active" data-type="radio" style="width:120px; !important">
    New
</label>
<label id="condition" class="btn btn-default toggle-class active" data-toggle="active" data-type="radio" style="width:120px; !important">
    Used
</label>

有人能帮我吗?

您可以使用jQuery data() 获得它

<label data-type="radio" id="myLabel">My Radio label</label>
<script type="text/javascript">
  $(function(){
      console.log($('#myLabel').data('type')); //Logs radio
  });
</script>

工作示例:https://jsfiddle.net/s31u5xu0/