zoukankan      html  css  js  c++  java
  • 通过JS动态创建和删除HTML元素

    <script type="text/javascript" language="Javascript">
    function InputOnBlur()
    {        var name=document.getElementById("name").value;

             if(name.length >10 || name.length<2)
                 {
                    var element=document.getElementById("message");
                if(element)
                {
                //alert(element.parentNode.innerHTML);
                element.parentNode.removeChild(element);
                }
                                 var MySpan=document.createElement("span");
                                 document.getElementById("containers").appendChild(MySpan);
                                 MySpan.id = "message";
                                 MySpan.innerHTML = "<img src='false.jpg' alt='请输入正确的姓名'/>请输入正确的姓名";
                    }
                    
             else{
                var element=document.getElementById("message");
                if(element)
                {
                //alert(element.innerHTML);
                element.parentNode.removeChild(element);
                }
                                 var MySpan=document.createElement("span");
                                 document.getElementById("containers").appendChild(MySpan);
                                 MySpan.id = "message";
                                 MySpan.innerHTML = "<img src='true.gif' alt='该用户名输入正确'/>该用户名输入正确";
                        }
    }
    </script>
     
     


    <div>    
    姓名:<input id="name" type="text" onblur="InputOnBlur()" /><span id="containers"></span></div>    
    <script language="javascript">    
    document.getElementById("containers").innerHTML = "<font color=red>请输入姓名</font>";    
    </script>   

  • 相关阅读:
    JS ipad图片拖动缩放 PHP
    PHP 格式化输出 PHP
    PHP Smarty模版使用 PHP
    PHP PDO小试 PHP
    PHP 获取网页所有连接 PHP
    C# 生成不重复随机字符串 (1秒内生成1000000个) PHP
    使用VS 开发PHP PHP
    PHP 扑捉未处理异常 PHP
    PHP 格式化MYSQL返回float类型 PHP
    CheckBox 选中判断及实现单选功能
  • 原文地址:https://www.cnblogs.com/focai/p/4094771.html
Copyright © 2011-2022 走看看