简体   繁体   English

HTML到使用JavaScript的XML转换?

[英]html to xml conversion using javascript?

Is it possible to convert all div child information into XML or JSON 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]);

there is property called outerHTML. 有一个名为externalHTML的属性。 It Sets or retrieves the object and its content in HTML. 它设置或检索HTML中的对象及其内容。 U can use it in following way. 您可以按以下方式使用它。 eg: 例如:

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

tip: p is your any tag ID in body of page. 提示:p是页面正文中的任何标签ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM