如何使用 jQuery 获得 DOM 元素的 ID?
在 jQuery 中,attr 方法用于获取第一个匹配元素的 id 属性。
$("btn1").attr("id")在您的示例中
示例
<html >
<head>
<title>iddom</title>
<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btn1').click(function () {
alert( $('#test').attr('id'));
});
});
</script>
</head>
<body>
<div id="test">
</div>
<button type="button" id="btn1">Click Here</button><br />
</body>
</html>
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP