JS判断某个标签是否存在

来源:互联网 发布:php授权验证怎么做 编辑:程序博客网 时间:2024/06/01 19:48

 

<%@ 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>

 

0 0