网格不能在这个(“怪癖”)模式错误中使用

时间:2022-05-23 20:58:34

I want to make grid with jquery.I read data from xml. when I run it on Chrome browser it works.But when I try it on IE it gives this error.

我想用jquery制作网格。我从xml中读取数据。当我在Chrome浏览器上运行它的时候,它是有效的。但是当我在IE上试的时候,它会产生这个错误。

Grid can not be used in this ('quirks') mode!

I write this code:

我写这段代码:

var datasource_url = "/Data/XML_Data.xml";

var datasource_url = " /数据/ XML_Data.xml”;

  function makeID(string) {
    return string.toLowerCase().replace(/\s/g, "_")
  }
  $(function() {
    $.loadGrid = function() {
      $.ajax({
        cache: false,
        url :datasource_url ,
        dataType: "xml",
        success: function(data, res) {

         var colNames = new Array;
          var colIDs = new Array;
          var colModel = new Array;
          var datas = new Array;
          var metadata = $(data).find("metadata").each(function() {
            $(this).find('item').each(function() {
              var colname = $(this).attr('name');
              var colid = makeID($(this).attr('name'));
              var coltype = $(this).attr('type');
              var collength = $(this).attr('length');
              var sorttype = null;
              var sortable = false;
              switch(coltype) {
                case "xs:double":
                  sorttype = "float";
                  sortable = true;
                  break;
                case "xs:string":
                default:
                  sorttype = "text";
                  sortable = true;
                  break;

              }
              colNames[colNames.length] = colname;
              colIDs[colIDs.length] = colid;
              colModel[colModel.length] = {name: colid, index: colid, width: 200, align: "center", sorttype: sorttype, sortable: sortable}
            });
          });
          var options = {
            datatype: "local",
            height: 500,
            colNames: colNames,
            colModel: colModel,
            multiselect: false,
            caption : "Data Grid",
            rowNum : 1000,
            rownumbers: true
          }
          $("#datagrid").jqGrid(options);
          $(data).find("data").each(function() {
            var i=0;
            $(this).find('row').each(function() {
              var idx = 0;
              var rowdata = new Object;
              $(this).find('value').each(function() {
                var ccolid = colIDs[idx];
                if (ccolid) {
                  rowdata[ccolid] = $(this).text();
                }
                idx++;
              })
              $("#datagrid").jqGrid('addRowData', i+1, rowdata)
              i++
            })
          })

        }
      })
    }
    $.loadGrid();
    /*
    $("#btnLoadGrid").click(function() { 
      //$(this).attr("disabled", "disabled")
      $.loadGrid();

    })
    */
  });


</script>

How can I fix this.

我怎样才能解决这个问题。

2 个解决方案

#1


10  

I recommend you to include

我建议你加入。

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

at the beginning of <head> of your XHTML document. It will switch off the "Compatibility View" for the page. Some time ago I included the line in all code examples which I found on the official jqGrid wiki (see here) because the problem which you describe is common.

在XHTML文档的开头。它将关闭页面的“兼容性视图”。不久前,我在官方jqGrid wiki上发现了所有代码示例中的一行,因为您所描述的问题很常见。

#2


1  

As mentioned in the comments, you'll need a correct doctype to force IE out of quirks mode. It looks like you are using an XHTML doctype, which is not compatible with some aspects of HTML5. Try using the HTML5 doctype on the first line of your HTML page: <!DOCTYPE html>

正如在评论中提到的,你需要一个正确的doctype来迫使IE退出。看起来您正在使用XHTML doctype,它与HTML5的某些方面不兼容。尝试在HTML页面的第一行使用HTML5 doctype:

Here's a good article on the different doctypes and their relationship to HTML5.

这里有一篇关于不同doctype及其与HTML5的关系的好文章。

#1


10  

I recommend you to include

我建议你加入。

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

at the beginning of <head> of your XHTML document. It will switch off the "Compatibility View" for the page. Some time ago I included the line in all code examples which I found on the official jqGrid wiki (see here) because the problem which you describe is common.

在XHTML文档的开头。它将关闭页面的“兼容性视图”。不久前,我在官方jqGrid wiki上发现了所有代码示例中的一行,因为您所描述的问题很常见。

#2


1  

As mentioned in the comments, you'll need a correct doctype to force IE out of quirks mode. It looks like you are using an XHTML doctype, which is not compatible with some aspects of HTML5. Try using the HTML5 doctype on the first line of your HTML page: <!DOCTYPE html>

正如在评论中提到的,你需要一个正确的doctype来迫使IE退出。看起来您正在使用XHTML doctype,它与HTML5的某些方面不兼容。尝试在HTML页面的第一行使用HTML5 doctype:

Here's a good article on the different doctypes and their relationship to HTML5.

这里有一篇关于不同doctype及其与HTML5的关系的好文章。