form表单元素判断在ie6中的bug

本文探讨了在Internet Explorer 6中使用JavaScript动态创建表单元素时遇到的问题,并对比了不同浏览器下的表现差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!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> <title>form表单元素判断在ie6中的bug</title> </head> <body> <form id="ff"></form> <mce:script type="text/javascript"><!-- function testfun() { var f = document.getElementById("ff"); if (f["detail"]) { f["detail"].value = "111"; } else { var o = document.createElement("input"); o.name = "detail"; f.appendChild(o); } } testfun(); testfun(); // --></mce:script> </body> </html>

第一次调用js会产生form的一个detail表单,第二次调用判断是否已经存在了。

在分firefox正常,在ie6里不正常。

我们再看一个代码:

<!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> <title>form表单元素判断在ie6中的bug</title> </head> <body> <form id="ff"> <input type="text" name="detail" /> </form> <mce:script type="text/javascript"><!-- function testfun() { var f = document.getElementById("ff"); if (f["detail"]) { f["detail"].value = "111"; } else { var o = document.createElement("input"); o.name = "detail"; f.appendChild(o); } } //testfun(); testfun(); // --></mce:script> </body> </html>

这个写法在ie6和firefox都显示正常。

两者比较一下,发现ie6就是这么垃圾,对于js动态写入的元素根本无法判断。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值