jQuery clone problem

前端 未结 4 897
予麋鹿
予麋鹿 2021-01-18 11:43

I am trying to clone a div and change the names of the input fields in this div. It works great for most of the browsers but IE 7 does not change the name attribute of the i

4条回答
  •  无人及你
    2021-01-18 12:10

    The simple solution for Radio button is :

    $("div:last").find("radio").each(function(){
         var name="someNewName";
         var id="someNewId";
        if (!$.browser.msie || parseInt($.browser.version) > 7) {
          this.name = name;
          this.id=id;
        }
        else {
          (this).attr("outerHTML", "");  
        }
    });
    

    This will alter the outerHTML of the element so that the HTML for the element(radio button) is overwritten. The same solution can be applied for : find("input") / find("checkbox") for the other controls too.

提交回复
热议问题