在IE下,用JQuery无法 修改input 的name属性
如题,下面是测试代码,先谢过!
[code=JScript]
<html>
<head>
<script type= "text/javascript " src= "jsframe/jquery-1.4.2.js "> </script>
<script type= "text/javascript ">
$(document).ready(function(){
var num = 1;
var data = ' <div> '
+ ' <input type=\ 'text\ ' name=\ 'n1\ ' value=\ 'san\ '/> '
+ ' <input type=\ 'text\ ' name=\ 'n2\ ' value=\ 'zhang\ '/> '
+ ' </div> ';
var temp = $(data);
alert(temp.html());//未修改前
temp.find( 'input ').each(function(){
$(this).attr( 'name ', 'f_ '+(num++));
$(this).attr( 'value ', 'v_ '+(num++));
//alert($(this).attr( 'name '));//这里显示修改后的值是正常的
});
alert(temp.html());//打印出的结果显示,在IE下name值未修改
});
</script>
</head>
<body>
</body>
</html>
[/code]
[解决办法]
这个码我运行时就已经有问题了. 如果data是字符串, 直接用正则在data中改值, 如果要通过jq索引DOM来改值, 最好把它append后再修改
[解决办法]
<div name="name1" id="id1">d</div><script type="text/javascript">alert(document.getElementById("id1").name); //显示name1document.getElementById("id1").name='name2';alert(document.getElementById("id1").name); //显示name2</script>
[解决办法]
可以用 obj.parentNode.replaceChild()
[解决办法]
http://msdn.microsoft.com/zh-cn/library/ms534700(en-us,VS.85).aspx
As of Microsoft Internet Explorer 5, the type property is read/write-once, but only when an input element is created with the createElement method and before it is added to the document.
name也一样