<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function abc()
{
var a=document.getElementById("test");
if (a != null) {
alert("不为空");
//不为空
}
else {
alert("为空");
//为空
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<br />
<div id="tetDiv" runat="server" style="background-color: Blue;">
测试层
</div>
<input type="button" value="点击" onclick="abc()" />
</div>
</form>
</body>
</html>
本文介绍了一个简单的ASP.NET WebForm页面如何通过JavaScript检查元素是否存在,并给出相应的提示。该示例使用了基本的HTML结构,结合服务器端C#代码以及客户端JavaScript脚本来实现元素状态的检查。
3707

被折叠的 条评论
为什么被折叠?



