0

我正在尝试在 HTML 上呈现 jqGrid,但遇到了一些错误。这是完整的代码。我收到运行时错误,并且网格未加载。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script src="/Scripts/jquery-1.3.2.js" type="text/javascript"></script>    
   <script src="/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>

    <link rel="stylesheet" type="text/css" href="/Scripts/themes/steel/grid.css" title="steel"media="screen" />

    <link href="/Scripts/themes/jqModal.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery.jqGrid.js" type="text/javascript"></script>
    <script src="/Scripts/js/jqModal.js" type="text/javascript"></script>
    <script src="/Scripts/js/jqDnR.js" type="text/javascript"></script>
    <script type="text/javascript">

    function() {

     var lastsel2 =
jQuery("#tempset").jqGrid({
    datatype: "local",
    height: 260,
    width:300,
       colNames:[ ' ','Rate *C/Min','Value *C', 'Hold Time min', 'Run Time min'],
       colModel:[
           {name:'id',index:'id', width:60, sorttype:"int", editable: true},
           {name:'rate',index:'rate', width:40,editable: true,editoptions:{size:"20",maxlength:"30"}},
           {name:'value',index:'value', width:40, editable: true,editoptions: {size:"20",maxlength:"30"}},
           {name:'holdtime',index:'holdtime', width:50, editable: true,editoptions:{size:"20",maxlength:"30"}},        
           {name:'runtime',index:'runtime', width:100,editable: false}        
       ],
    onSelectRow: function(id){
        if(id && id!==lastsel2){
            jQuery('#tempset').jqGrid('restoreRow',lastsel2);
            jQuery('#tempset').jqGrid('editRow',id,true);
            lastsel2=id;
        }
    },
    //editurl: "server.php",
    caption: "Temperature Settings",
    pager: "#tempset_pager",
});

var mydata2 = [
        {id:"initial",rate:"",value:"50",holdtime:"60",runtime:"60"},
        {id:"Ramp 1",rate:"15",value:"67 ",holdtime:"5",runtime:"66.133"},
        {id:"Ramp 2",rate:"20",value:"89",holdtime:"10",runtime:"77.233"},
        {id:"Ramp 3",rate:"25",value:"123",holdtime:"3",runtime:"81.593"}
        ];

for(var i=0;i < mydata2.length;i++)
{
//alert(mydata2[i].id);
 jQuery("#tempset").jqGrid('addRowData',mydata2[i].id,mydata2[i]);
 }

 jQuery("#tempset").navGrid("#tempset_pager", {});

 }

</script>
</head>


<body>
<div style = "margin-left:240px; top: 15px; position:absolute;">
 <table id="tempset"></table>
        <div id="tempset_pager"> </div>
 </div>


</body>
</html>
4

3 回答 3

1

以下可能会导致问题:

  1. 对 jQuery 的多次引用。
  2. function() { ...-> 这是一个语法错误。缺少函数名。
  3. pager: "#tempset_pager",-> 尾随逗号会在 IE 中出错
于 2013-01-02T11:24:22.273 回答
0

更换你的

function() { 

有了这个

$(function(){

并在脚本代码的末尾添加如下所示的右大括号

);

也换

var lastsel2 = 

var lastsel2;

注意:进行上述更改后,它对我有用

于 2013-01-02T11:30:48.800 回答
0

替换这个

function() {

有了这个

$(function(){

此外,替换var lastsel2 =var lastsel2;orvar lastsel2 = '';并重试。

于 2013-01-02T11:33:28.610 回答