Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尝试使用.HTML()在变量中编写HTML_Javascript_Jquery_Html - Fatal编程技术网

Javascript 尝试使用.HTML()在变量中编写HTML

Javascript 尝试使用.HTML()在变量中编写HTML,javascript,jquery,html,Javascript,Jquery,Html,我试图将存储在变量中的HTML写入主容器,但当我写入时,主容器最终为空 我在console.log中记录了变量,它包含html,但当我在下一行将它作为.html()函数的参数/参数传递时,当代码运行时,选择器的html为空,而不是变量中的html 以下是重现问题所需的操作: 请访问此页面: 向左或向右拖动其中一张牌 在6秒钟内,单击顶部通知中的“撤消”按钮或文本 见证主容器的html变为空 我试图做的是在刷卡之前恢复到html;因此,模拟撤销 这里是创建通知的jQuery/javascript代

我试图将存储在变量中的HTML写入主容器,但当我写入时,主容器最终为空

我在console.log中记录了变量,它包含html,但当我在下一行将它作为
.html()
函数的参数/参数传递时,当代码运行时,选择器的html为空,而不是变量中的html

以下是重现问题所需的操作:

  • 请访问此页面:
  • 向左或向右拖动其中一张牌
  • 在6秒钟内,单击顶部通知中的“撤消”按钮或文本
  • 见证主容器的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
        }
    });
    
    $.createNotification({
    水平:“居中”,//水平居中通知
    垂直:“顶部”,//顶部对齐通知
    内容:'卡片已解除。撤消↩', // 通知内容
    持续时间:6000,//通知持续6秒
    click:function(){//单击通知后要执行的操作
    $('#main').html(mainHTML);//编写html,这里是#main变为空的地方
    console.log(mainHTML);//但是这个console.log显示mainHTML在变量中有正确的HTML
    log(“中断时间!#4”);//随机调试行
    var a=$('.lastCardDrawed').attr('data-cardNumber');//从已刷卡的卡阵列中删除重写的卡
    对于(变量b=0,c=SwipedayCards.length;b
    分配已保存标记的语句确实有效。然而,再往前一点,您的代码检测到窗口比某个阈值宽,它清空了“main”元素中的“left”和“right”容器。

    我们可以看到a)如何创建
    mainHTML
    和b)如何/在何处调用$.createNotification?
    $('#left,#right').html(“”)这是导致它的代码,正如Pointy所示。@JamesLai mainHTML是由'var mainHTML=$('#main').html();'创建的开始拖动其中一张牌时。这就是createNotification的调用方式,就像那样。@melc什么行号?