开发者

jquery: name change of cloned object not working in IE?

开发者 https://www.devze.com 2023-01-11 11:27 出处:网络
Via jQuery I\'m dynamically cloning an input checkbox object开发者_Go百科, and then I\'m changing its name using this instruction:

Via jQuery I'm dynamically cloning an input checkbox object开发者_Go百科, and then I'm changing its name using this instruction:

row.find('[name="ACCCHB_CDARM"]').attr("name",id);

ACCCHB_CDARM is the attribute's name of object I'm cloning.

There's no problem using FireFox, but in IE it doesn't change the original value!

Is this code correct?

Thank you very much. Mirco


To reproduce your error, I've written the following code, which works just fine with Internet Explorer 8.0:

<script type="text/javascript">
    $(document).ready(function(){
        var row = $('#row');
        var inp = row.find('[name="ACCCHB_CDARM"]');
        inp.attr("name","NewName");
        alert(inp.attr("name"));
    });
</script>
<div id="row">
    <input type="checkbox" name="ACCCHB_CDARM" />
</div>

NewValue is alerted after changing the name attribute to NewValue.

It looks like that on older versions of Internet Explorer, the name attribute couldn't be changed dynamically (the post dates back from the year 2005). The current MSDN documentation for name states the following:

Microsoft JScript allows the name to be changed at run time

Further down in the documentation, where some examples are shown on how to dynamically change the name attribute you'll find the following line:

This feature requires Windows Internet Explorer 7 or later

To bring my answer to the point, it looks like you're using an older version of Internet Explorer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号