[英]Prevent content to be duplicated when clicking multiple times with Jquery/javascript
This is an extension to this question How to get value from nested HTML tag with Jquery/Javascript 这是此问题的扩展如何使用Jquery / Javascript从嵌套HTML标记中获取价值
When I execute the following script after the first time, the <h2>
-tags get duplicated multiple, though I only want the three values displayed... 第一次执行以下脚本时,
<h2>
-tags会重复多个,尽管我只希望显示三个值...
so my question is, what is going wrong here? 所以我的问题是,这里出了什么问题?
$(document).ready(function () {
$('.submit').on('click', function () {
$('#newLoanDiv').append('<div id="test"></div>');
$('.results-page').contents().appendTo($('#test'));
setTimeout( function(){
$('.submit').removeAttr('disabled');
$('.sums').find('dl').each(function () {
$('<h2 class="value">' + $(this).find('dd').text() + '</h2>').insertBefore('#test');
});
}, 100 );
});
});
Any help is appreciated... 任何帮助表示赞赏...
Try the following. 尝试以下方法。 Try
$('#test').empty();
尝试
$('#test').empty();
to clear data of the #test
on every click. 清除每次点击中
#test
数据。
$('.submit').on('click', function () {
$('#newLoanDiv').append('<div id="test"></div>');
$('#test').empty();
$('.results-page').contents().appendTo($('#test'));
setTimeout( function(){
$('.submit').removeAttr('disabled');
$('.sums').find('dl').each(function () {
$('<h2 class="value">' + $(this).find('dd').text() + '</h2>').insertBefore('#test');
});
}, 100 );
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.