您的位置:首页 > 其它

解决通过createElement创建出来的radio无法选中的问题

2008-10-27 14:29 337 查看
开发过程中,需要使用JS向页面动态添加radio,实现时通过document.createElement()方法来实现,刚开始的代码如下:

Code

if(document.uniqueID) {

//IE浏览器分支

var _radio = document.createElement("<input type='radio' name='_radio'>");

document.body.appendChild(_radio);

_radio = document.createElement("<input type='radio' name='_radio'>");

document.body.appendChild(_radio);

} else {

//非IE浏览器分支

var _radio = document.createElement("input");

_radio.type = "radio";

_radio.name = "_radio";

document.body.appendChild(_radio);

_radio = document.createElement("input");

_radio.type = "radio";

_radio.name = "_radio";

document.body.appendChild(_radio);

}

此外,在IE浏览中,通过document.createElement("input")来生成的radio和checkbox都无法通过document.getElementsByName()方法来获取。

摘:http://hotpepper.javaeye.com/blog/236338
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐