在jQuery中使用“ click”事件时如何获取元素的属性?
要获取元素的属性,请使用attr()jQuery中的方法。您可以尝试使用'click'事件运行以下代码以获取元素的属性-
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("Width of image: " + $("img").attr("width"));
});
});
</script>
</head>
<body>
<img src="/videotutorials/images/coding_ground_home.jpg" alt="Coding Ground" width="284" height="280"><br>
<button>Get Width</button>
</body>
</html>热门推荐
10 科学老师结婚祝福语简短
11 高考祝福语 简短12字
12 经典祝福语简短情侣句子
13 春节拜年祝福语儿童简短
14 小伙买车祝福语大全简短
15 升职祝福语朋友简短精辟
16 猪年幽默祝福语简短
17 哥哥新婚祝福语创意简短
18 虎年伊始祝福语大全简短