测试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 妈妈生日祝福语简短励志