且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery将HTML表转换为XML

更新时间:2023-02-03 13:08:09

如果我正确理解了您的问题,则需要在循环内创建<schedule>元素:

If I understand your question correctly, you need to create the <schedule> elements inside your loop:

$("#load_get").click(function() {
    var xml = "";
    $("#result tr").each(function() {
        var cells = $("td", this);
        if (cells.length > 0) {
            xml += "<schedule name='" + cells.eq(0).text() + "'>\n";
            for (var i = 1; i < cells.length; ++i) {
                xml += "\t<data>" + cells.eq(i).text() + "</data>\n";
            }
            xml += "</schedule>\n";
        }
    });
    window.alert(xml);
});