我正在尝试将存储在变量中的HTML写入主容器,但是当我写它时,主容器结束为空。
我控制了。记录了变量并且它包含了html,但是当我将它作为.html()
函数的参数/参数传递给下一行时,当代码运行时,选择器的html是空,而不是变量中的那个html。
以下是重新创建问题所需要做的事情:
我要做的是在卡被刷掉之前恢复到html;因此,模拟撤消。
这是一个创建通知的jQuery / javascript片段
$.createNotification({
horizontal: 'center', // horizontally centre notification
vertical: 'top', // top align notification
content: 'Card Dismissed.<span style="cursor:pointer; margin-left:32px;">Undo ↩</span>', // content of notification
duration: 6000, // 6 seconds notification lasts
click: function () { // what to do on notification once it is clicked
$('#main').html(mainHTML); // write the html, here is where #main becomes empty
console.log(mainHTML); // but this console.log shows that mainHTML has the right HTML in the variable
console.log("break-time! #4"); // random debugging line
var a = $('.lastCardDragged').attr('data-cardNumber'); // removes rewritten card from an array of cards that have been swiped away
for (var b = 0, c = swipedAwayCards.length; b < c; b++) {
if (swipedAwayCards[b] == a) {
swipedAwayCards.splice(b, 1);
break;
}
};
/* More code that sorts the cards and write the layouts into one or two columns */
this.hide(); // hide notification
}
});
答案 0 :(得分:2)
分配已保存标记的语句 有效。但是,稍微进一步,您的代码检测到窗口宽度超过某个阈值,并且它会清空“main”元素中的“left”和“right”容器。