JavaScript中如何获取按钮所在DIV的ID或NAME?

来源:互联网 发布:淘宝立即购买按钮代码 编辑:程序博客网 时间:2024/05/16 01:40
<html>
<head>
<title>这是一段测试代码,直接保存为html文件运行</title>
<script>
function test(id){
var s;
s=document.getElementById(id).parentElement.id;‍document.getElementById("Label1").innerHTML="测试成功!";
alert(s);
}
</script>
</head>
<body>
<div id="div_test">
<input type="button" id="btn_test" value="test" onclick="test(this.id)"/>‍<asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label>
</div>
</body>
</html>