FF下innerHTML获取不到input标签中value的值解决办法

页面代码:

<div id="divid">

<input type="text" value="" id="testid" />

</div>

很多时候,,,页面上input标签中的value需要通过javascript动态设置其值:document.getElementById('testid').value='test value';

通过document.getElementById(‘divid’).innerHTML:

IE下:<input type="text" value="test value" id="testid" />

FF下:<input type="text" value="" id="testid" />


这就达不到我们想要的效果。。。。。


解决办法:

document.getElementById('testid').value='test value';

修改为:

var testid = document.getElementById('testid');

testid.value = "test value";

testid.setAttribute("value", testid.value);

这样就通过innerHTML在FF下就可以获取和IE下一样的效果了。。。。。



<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>注册界面</title> </head> <body> <div id="register_div" style="margin-left: 8cm;"> <h1 style="color: burlywood; margin: left 2cm;;">用户注册</h1> <form action="test.html" method="post" onsubmit="return check()"> <label>用户账号:</label> <input id="account" type="text" style="height: 0.65cm;border-color:cadetblue;border-radius: 0.25cm;margin: 0.3cm;"/><span id="account_info"></span></br> <label>用户邮箱:</label> <input id="email" type="email"style="height: 0.65cm;border-color:cadetblue;border-radius: 0.25cm;margin: 0.3cm;"/><span id="account_info"></span></br> <label>用户号码:</label> <input id="mobile" type="text"style="height: 0.65cm;border-color:cadetblue;border-radius: 0.25cm;margin: 0.3cm;"/><span id="account_info"></span></br> <label>用户密码:</label> <input id="password" type="password"style="height: 0.65cm;border-color:cadetblue;border-radius: 0.25cm;margin: 0.3cm;"/><span id="account_info"></span></br> <label>确认密码:</label> <input id="repassword" type="password"style="height: 0.65cm;border-color:cadetblue;border-radius: 0.25cm;margin: 0.3cm;"/><span id="account_info"></span></br> <input type="submit" value="注册" style="margin-left: 2.5cm;height: 1cm;width: 2cm; background-color:darkcyan; border-radius: 0.25cm;" /> </form> </div> <script type="text/javascript"> function check(){ var account =document.getElementById("account").value var account_patt=/^[a-zA-Z]+[0-9]+[a-zA-Z]*/ if(account ==""){ document.getElementById("account_info").innerHTML="<font color='red'>账号不能为空</font>" return false }else if(account.length<3 ||account.length>10){ document.getElementById("account_info").innerHTML="<font color='red'>账号的长度必须要在3-10</font>" return false }else if(account_patt.test((account))){ document.getElementById("account_info").innerHTML="<font color='red'>账号以字母开头包含数字,且长度在3-10之间</font>" return false } return tr
04-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值