0

我正在尝试删除与 eng_app 关联的 id 属性下面的代码有什么问题我仍然看到 id 属性。如果我看到里面的日志

这是我到目前为止尝试过的代码

 var htm = $("#addin").find(".eng_data:first-child").html();
 if($(htm).find(".eng_app"))
 {
    console.log("Inside if");
console.log($(this).removeAttr("id"));
 }
 var new_htm = "<div class='eng_data'>" +htm+"</div>";                                  
 $("#addin").append(new_htm);   

HTML:

 <div id="eng_data" class="eng_data">


      <select class="eng_app">
      <option value="-1" selected="">Choose application</option>
      </select>
      <input type="text" class="grades"  placeholder="grades"/>
      <a href="#" ><img src="images/add.gif" width="21" class="addrow"/></a>

      </div>
4

4 回答 4

0

试试这个 :

$(htm).find(".eng_app").removeAttr('id');

希望它会有所帮助

于 2013-07-30T08:01:47.337 回答
0

你应该做这个:

$(htm).find(".eng_app").removeAttr('id');
console.log($(htm).find(".eng_app").attr('id'));
于 2013-07-30T08:02:15.963 回答
0

试试这个:

var htm = $("#addin").find(".eng_data:first-child").html();
var eng_app = $(htm).find(".eng_app");
if (eng_app.length > 0)
{
    eng_app.removeAttr("id");
    console.log(eng_app.attr("id"));
}
var new_htm = "<div class='eng_data'>" + htm + "</div>";                                  
$("#addin").append(new_htm);

你的问题是:

  1. if($(htm).find(".eng_app"))将始终返回 true,因为即使没有匹配项,它也会创建一个空数组。我的建议length改为测试。
  2. 我不认为您处于this已映射的上下文中,因此它仍然只是引用该window对象。

希望这可以帮助。

于 2013-07-30T08:10:46.170 回答
0

试试这个

$("#addin").find(".eng_data:first-child").children(".eng_app").removeAttr('id');

希望它会奏效。

于 2013-07-30T08:11:36.720 回答