我想将卡片附加到另一个HTML页面

时间:2019-06-18 10:18:08

标签: html

  

在这里,我现在想从一个html获取所有值,然后追加到另一个html页面。我该怎么办?

$('.fa-cart-plus ').click(function () {
    var images = $(this).attr('src');
    var price = $(this).attr('data-name');
    var con = $(this, '.modal-body>p').parent().html();
    $('#tom').append("<div class='card' data-name=" + price + " > <button type='button' class='close' data-dismiss='modal'>&times;</button><img src=" + images + " ><div>" + con + "</div></div > ")

});

1 个答案:

答案 0 :(得分:0)

如果我对您的理解正确,则您的应用中有两个html文件,并且您希望重定向时第一页上的内容可以在另一页上显示。
如果是这样,则需要保存数据,因为重定向时丢失数据。
最好的方法是将数据保存到后端数据库。但是,如果没有数据库,则可以使用localStorage
试试这个:

// ......
var con = $(this, '.modal-body>p').parent().html();
var cards=[];   // Added code from here
cards.append("{your_content}");    //Replace `{your-content}` with your content
localStorage.setItem('cards', {cards});

现在,在另一条路线上,您可以使用以下命令从其中获取数据:

const cards = localStorage.getItem('cards');
$("#tom").html(cards);

引用:https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

希望有帮助。干杯!