jQuery convert HTML Table to XML

后端 未结 4 1331
时光取名叫无心
时光取名叫无心 2021-01-22 00:17

I am retrieving HTML from a remote host with the following jQuery code

    var loadUrl = \"URL.html\"; 
        $(\"#result\")
        .html(ajax_load)
        .load(         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-22 00:37

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

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

提交回复
热议问题