当我的URL包含特定字符串时,我想调用一个变量,该变量存储一些带有一些数据的html标记。在我执行超时功能后,数据可以访问,并且控制台会吐出正确的标记。
var mapData = setTimeout(function() {
var mapContent = $('.case__map').html(); // THIS DATA I WANT
},3000)
if (window.location.search == '?print=1') {
$('.presentation-list').find('[data-type="image"]').each(function () {
var src = $(this).attr('data-src');
$('.newData').append('<div><img src="' + src+ '"/></div>')
});
// HERE I WANT TO APPEND THE DATA INSIDE "MAPCONTENT" TO A NEW DIV
// HOW TO ACHIEVE THIS?
}
感谢任何帮助
答案 0 :(得分:1)
您可以在函数超时后包装想要执行的操作,并在超时函数中调用它。
var mapData = setTimeout(function() {
var mapContent = $('.case__map').html(); // THIS DATA I WANT
appendData(mapContent);
},3000)
if (window.location.search == '?print=1') {
$('.presentation-list').find('[data-type="image"]').each(function () {
var src = $(this).attr('data-src');
$('.newData').append('<div><img src="' + src+ '"/></div>')
});
}
function appendData(data) {
if (window.location.search == '?print=1') {
// append data where you want.
// HERE I WANT TO APPEND THE DATA INSIDE "MAPCONTENT" TO A NEW DIV
// HOW TO ACHIEVE THIS?
}
}