我有这个 HTML
<div id='add_more_edu'>
<div class='one_exp'>
--- many INPUT and SELECT elements with disabled attribute
</div>
</div>
我的页面上有一个按钮,单击时会调用一个函数,该函数的代码如下所示。
var edu_contect = $("#add_more_edu").clone().html();
// Line # 2
edu_contect = $(edu_contect).find("input,select").removeAttr('disabled');
$('.edu_history_div').append(edu_contect);
字段被成功禁用,但我在 .edu_history_div
中附加的内容是这样的
<div id='add_more_edu'>
--- many INPUT and SELECT elements with disabled attribute
</div>
<div class='one_exp'>
消失。
如果我评论Line # 2
然后 <div class='one_exp'>
不会消失。
解决方案是什么?
或者
这条线的任何替代品
edu_contect = $(edu_contect).find("input,select").removeAttr('disabled');
???
我试过了
$(edu_contect).find("input,select").removeAttr('disabled');
和<div class='one_exp'>
没关系,但是 Disabled
属性未从 input
中删除和 select
最佳答案
$(edu_contect)
上的 find()
仅返回匹配的元素,在您的情况下是输入和选择,这些元素存储在 edu_contect
行 edu_contect = ...
。
此外,这里不需要html()
,因为可以在.clone()
返回的对象。
使用以下内容
var edu_contect = $("#add_more_edu").clone();
edu_contect.find("input,select").removeAttr('disabled')
$('.edu_history_div').append(edu_contect);
关于javascript - find() 从存储在变量中的 HTML 中删除直接标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31284061/