jquery读取XML 生成页面文件

时间:2023-01-11 19:05:47
    $.get("../../js/data.xml", function (xml) {
        $(xml).find("local").each(function () {
            var local = $(this);
           var company = local.children();
                $.each(company, function () {
                    var c = $(this);
                    var dept = $(this).children();
//这里的取值方法现在只兼容IE。
var _html = "<li><input class=\"cssCompany\" name=\"inputCompany\" id=\"" + c.attr("id") + "\" type=\"checkbox\" value=\"\" /><img src=\"../../images/" + c.attr("src") + "\" /></li>" $("#showCompany").append(_html); $.each(dept, function (i, val) { var id = $(this).attr("id"); var pid = $(this).attr("pid");
              //这里的取值方法只兼容IE。其他浏览器可能需要换属性名才能取到值
var _htmlDept = "<li><input name=\"deptids\" id=\"" + id + "\" pid=\"" + pid + "\" type=\"checkbox\" value=\""+id+"\" />" + val.text + "</li>" $("#showDept").append(_htmlDept); }) }) })
<local name="郑州市">
    <company name="郑州总公司" id="61" src="logo_shouqi.jpg" shortName="郑州总公司">
      <dept id="41" pid="61">新郑门店</dept>
    </company>
  </local>