簡體   English   中英

HTML到使用JavaScript的XML轉換?

[英]html to xml conversion using javascript?

是否可以使用JavaScript將所有div子級信息轉換為XML或JSON?

$("#droppable").droppable({
drop : function(event, ui) {
    var id = $(ui.draggable).attr("id");
    var cloneObj = $((ui.draggable).clone());
    $(cloneObj).removeClass("draggable ui-draggable");
    if (id === "txt") {
        inputOBj = document.createElement("input");
        inputOBj.setAttribute("id", "txt" + i);
        $("#droppable").append(inputOBj);
    } else if (id == "combo") {
        inputOBj = document.createElement("select");
        inputOBj.setAttribute("id", "select" + i);
        console.log("");
    }
  });

我相信您可以使用XMLSerializer來做到這一點。

var yourString = new XMLSerializer().serializeToString(cloneObj[0]);

有一個名為externalHTML的屬性。 它設置或檢索HTML中的對象及其內容。 您可以按以下方式使用它。 例如:

$(document).ready(function() {  
    $('#p').click(function() {
        alert($('#p')[0].outerHTML);
    }); 
});

提示:p是頁面正文中的任何標簽ID。

暫無
暫無

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

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