簡體   English   中英

如何將數據追加到div?

[英]How to Append the data to a div?

我有一個函數,在單擊按鈕時添加列,現在我想要的是在按鈕上單擊要添加的列,在我的情況下,我希望將其附加到另一個div上,此時按鈕和附加數據都同時添加到同一個div中

這是我正在處理的代碼

var i = 1;
$(document).ready(function() {             
    $("button[id='columnadd']").click(function () {
       // create the element
       var domElement = $('<div id="shoppingCart' + i++ + '" class="shoppingCart"><h2 class="ui-widget-header">Add Menu Items Here</h2><aside class="ui-widget-content" id="droppable"><ol><li class="placeholder">Add your items here</li></ol></aside></div>');

       $(this).after(domElement);
       // at this point you have domElement in your page
       //.appendTo("#columnhoder")
       // make it droppable
       domElement.find("ol").droppable({
           accept: '.small_box li',
           greedy: true,
           drop: function (event, ui) {
               alert(1);
               makeItDroppableToo(event, ui, this);
               //$(this).find(".placeholder").remove();
               //$("<li></li>").text(ui.draggable.text()).appendTo(this);                         
           }
       });
});

我要這個

var domElement = $('<div id="shoppingCart' + i++ + '" class="shoppingCart"><h2 class="ui-widget-header">Add Menu Items Here</h2><aside class="ui-widget-content" id="droppable"><ol><li class="placeholder">Add your items here</li></ol></aside></div>'); 

追加到這個div

<div id="columnholder">div>

您可以使用appendTo:

domElement.appendTo('#columnholder');

$("#columnholder").append(domElement)應該可以工作

jQuery追加

使用jQuery,這非常容易。 您只需要選擇容器,然后在其上使用append方法即可。 例如:

$('#columnholder').append('your html code or something like that');

看看: http : //api.jquery.com/append/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM