测试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 心媳妇生日祝福语简短