测试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 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短