reset的失效问题

 

在 DOM 中,表单重置非常简单,使用 <input type=”reset”> 或者 <button type=”reset”> 即可。原生 DOM 也提供了 reset() 方法用于表单重置。

但是在 Firefox/Chrome 浏览器中,如果字段是隐藏域(type=”hidden”)的话,使用 reset 是无法将字段值还原为初始值的。但在 IE6/7/8 中都可以重置。

目前得到的解决方案是

<input type="text" name="aa" style="display:none;">
下面我给出一个完整的测试例子,我在ie和标准浏览器等数十种浏览器下面没有发现任何问题,有需要的同学们可以参考
 
<!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>
function inputValue(){
	document.getElementById("aa").value="123456";
}
function showValue(){
	alert(document.getElementById("aa").value);
	}
</script>
<style>
#aa{
	display:none;
	}
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <input type="text" name="textfield" id="textfield" />
  <input type="text" name="textfield2" id="textfield2" />
  <input type="text" name="textfield2" value="nnn" id="aa" />
  <input type="button" onclick="inputValue()" value="value" />
  <input type="submit" name="button" id="button" value="提交" />
  <input type="reset" name="button2" id="button2" value="重置" />
</form>
<a href="javascript:showValue()">show value</a>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值