如何在 jQuery 中获取自定义属性的值?
jqueryweb developmentfront end technology
要在 jQuery 中获取值,请使用 data-attributes 属性及其 data() 方法。您可以尝试运行以下代码来实现如何获取自定义属性的值:
示例
<html>
<head>
<title>Selector Example</title>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
alert($('#my_id').data('original-title'));
});
</script>
</head>
<body>
<strong id="my_id" data-original-title="Hello">Demo</strong>
</body>
</html>

