jQuery convert HTML Table to XML

后端 未结 4 1332
时光取名叫无心
时光取名叫无心 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:50

    Try this:

    $(function(){
        var xml = "";
        $('tr:not(:first)').each(function(i, tr){
            $tr = $(tr);
            var index = $.trim($tr.find('td:first').text());
            xml += '';
            $tr.find('td:not(:first)').each(function(j, td){
                xml += '';
                xml += $.trim($(td).text());
                xml += '';
            });
            xml += '';
        });
        alert(xml);
    });
    

    Example here.

    If you'd be using and you could still simplify it slightly further.

提交回复
热议问题