测试HTML属性tabindex是否存在并获取值
要获取HTML属性的值,请尝试以下操作:
$("#demo").attr("tabindex")该attr()方法可用于从匹配集中的第一个元素中获取属性的值,或将属性值设置到所有匹配元素上。
您也可以使用该hasAttribute()方法查看元素是否有属性。
示例
尝试运行以下代码以了解如何使用hasAttribute()方法:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('button').on('click', function() {
if (this.hasAttribute("style")) {
alert('True')
} else {
alert('False')
}
})
});
</script>
</head>
<body>
<button class = 'button' style = 'background-color:blue;'>
Button
</button>
<button class = 'button'>
Button 2
</button>
</body>
</html>热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语