您可以在加载时将父div的html存储在变量中,当您想要重置div时,您可以只将html内容从变量加载到div中。
为父容器id="choice_div"提供一个id
代码语言:javascript复制
代码语言:javascript复制var choice_div_html;
function resetChoicediv(){
$('#choice_div').html(window.choice_div_html);
}
$(function(){
window.choice_div_html = $('#choice_div').html();
})
代码语言:javascript复制.box {
display:block;
border:1px solid red;
margin:5px;
}
.box span {
display:block;
padding:5px;
border:1px dashed blue;
margin:2px;
}
.removeBtn {
color:red;
float:right;
}代码语言:javascript复制
Choice1
Choice2
Choice3
Choice1
Choice2
Choice3
Choice4
Choice1
Choice2
Choice3
Choice4
Choice5
Choice1
Choice2
Choice3
Choice4
Choice5
Choice6
Choice1
Choice2
Choice3
Choice4
Choice5
Choice6
Choice7
Choice1
Choice2
Choice3
Choice4
Choice5
Choice6
Choice7
Choice8
Choice1
Choice2
Choice3
Choice4
Choice5
Choice6
Choice7
Choice8
Choice9
var choice_div_html;
function resetChoicediv() {
$('#choice_div').html(window.choice_div_html);
}
$(function() {
window.choice_div_html = $('#choice_div').html();
//adding remove buttons for each choice for testing...
addremovebuttons();
})
//test - add remove btn
function addremovebuttons() {
$('#choice_div').find('span').each(function() {
if ($(this).find('.removeBtn').length == 0) {
$(this).append('');
}
});
}