我有一个包含输入元素的克隆div,所有这些都被禁用.我试图使用以下JQuery代码删除每个div的子项的禁用属性.
clonedElement.children().removeAttr('disabled');
Run Code Online (Sandbox Code Playgroud)
我没有大量的JQuery经验,所以我可能误解了它的工作方式.我应该如何从克隆节点的所有子节点中删除"disabled"属性?
如果有帮助,clonedElement是使用JQuery .clone()方法创建的.
用于测试的HTML ---
<div id="original_item" class="hidden">
<div class="row_submit">
<div class="med_field">
<p>Product:</p>
<select name="product[]">
<option></option>
</select>
</div>
<div class="small_field">
<p>Type:</p>
<select name="type[]">
<option></option>
</select>
</div>
<div class="small_field">
<p>Price:</p>
<input type="text" name="price[]" value="test" disabled="disabled" />
</div>
<div class="small_field">
<p>Quantity:</p>
<input type="text" name="quantity[]" />
</div>
<img onclick="removeItem(this);" title="Remove Item" style="margin: 18px 0 0 12px;" src="icons/cancel.gif" />
</div>
<input type="hidden" name="warehouse_data[]" />
</div>
Run Code Online (Sandbox Code Playgroud)
children只查看直接子项,如果clonedElement不是med_field/small-field之一,那么它将无效.
您可以使用它find()来搜索直接孩子之外的元素.
即
//for jQuery < 1.6
$("*", clonedElement).removeAttr("disabled");
//or
clonedElement.find("*").removeAttr("disabled");
//for jQuery >= 1.6
$("*", clonedElement).removeProp("disabled");
//or
clonedElement.find("*").removeProp("disabled");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6485 次 |
| 最近记录: |