原生的input输入后显示删除按钮
JavaScript Code
- <script type="text/javascript">
- document.getElementById("search").addEventListener("keyup",function(){
- if(this.value.length>0)
- {
- document.getElementById("cls").style.visibility="visible";
- document.getElementById("cls").onclick=function()
- {
- document.getElementById("search").value="";
- }
- }else
- {
- document.getElementById("cls").style.visibility="hidden";
- }
- });
- </script>
XML/HTML Code
- <div id="baidu">
- <div class="input">
- <input type="text" id="search"><span class="clear" id="cls">X</span>
- </div>
- <button>搜索</button>
- </div>
原文地址:http://www.freejs.net/article_biaodan_596.html