js或者jquery清空文本框所有内容

来源:互联网 发布:安卓 传送gson数据 编辑:程序博客网 时间:2024/04/29 21:52

js或者jquery清空文本框所有内容

reset只能重置文本框的内容,有时候不满足我们的需求,可以使用如下方法进行清空文本框的内容:

jquery实现:

<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script type="text/javascript">$(document).ready(function(){ $(function(){   $('input:reset').click(function(){     $('.input').val("");    });  });  });</script></head><body><input size="72" class="input" maxlength="64" name="aaa" type="text" value="nihao"><input size="72" class="input" maxlength="64" name="bbb" type="text" value="nihao2"><input size="72" class="input" maxlength="64" name="ccc" type="text" value="nihao3"><input value="清空全部" onClick="" type="reset"></body></html>

javascript实现:只清空input的type 是text 文本框的内容

<!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><script LANGUAGE="JavaScript">function doReset(){for(i=0;i<document.all.tags("input").length;i++){if(document.all.tags("input")[i].type=="text"){document.all.tags("input")[i].value="";}}}</script></head><body><input size="72" class="input" maxlength="64" name="aaa" type="text" value="nihao"><input size="72" class="input" maxlength="64" name="bbb" type="text" value="nihao2"><input size="72" class="input" maxlength="64" name="ccc" type="text" value="nihao3"><input value="清空全部" onClick="doReset()" type="button"></body></html>



原创粉丝点击