how to get the data from custom data tag in jquery

This question already has an answer here:

  • “Thinking in AngularJS” if I have a jQuery background? [closed] 15 answers

  • 你可以简单地使用jquery .attr来获得所需的输出。

    console.log($("#val").attr('data-tabval'))
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <a href="#angular_code" role="tab" id="angular_code-tab" data-toggle="tab" aria-controls="angular_code">
       <span id="val" data-tabval="test123" class="text">test here</span>
    </a>

    以下是您的要求的代码片段:

    var value = $("#val").attr("data-tabval");
    

    you can Gate custom Attribute value this code example:

    $("a").click(function(event) {
          alert($(this).attr("aria-controls"));
          alert($(this).attr(" data-toggle"));
    });
    

    And others attribute or custom attribute

    链接地址: http://www.djcxy.com/p/3926.html

    上一篇: 框架和库之间有什么区别?

    下一篇: 如何从jquery中的自定义数据标签中获取数据