2013-01-17 54 views
0

我试图从.js文件加载.htm模板。但是在.htm文件中有一个脚本,当模板被加载并且事情很流畅时,脚本会获取触发器。从.js文件加载脚本

这里是模板的外观。 testing.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>http://stackoverflow.com/questions/6946559/jqgrid-please-help</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <script type="text/javascript" charset="utf-8"> 
      $(document).ready(function() { 
       $('#example').dataTable({ 
        "bProcessing": true, 
        "sAjaxSource": '/Home/GetData', 
        "sScrollY": "400px", 
        "sScrollX": "200px", 
        "bPaginate": false 
       }); 
      }); 
     </script> 

</head> 
<div id="dynamic"> 
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"> 
    <thead> 
     <tr> 
      <th width="20%">Date</th> 
      <th width="25%">Name</th> 
      <th width="25%">ProposalID</th> 
      <th width="25%">Time</th> 
       </tr> 
    </thead> 
    <tbody> 
    </tbody> 

</table> 
</div> 
</html> 

这是加载模板的.js文件。

var iTabs = function() { 
    return { 
     Init: function() { 

      var placeholder = $("#testtab"); 
      placeholder.setTemplateURL("/Templates/Home/testing.htm"); 

      placeholder.load("/Templates/Home/testing.htm"); 


     } 
    } 
}(); 

但是,现在我想在.js文件中执行.htm脚本,即加载模板后。 如果我只运行一个脚本即

$('#example').dataTable({ 
         "bProcessing": true, 
         "sAjaxSource": '/Home/GetData', 
         "sScrollY": "400px", 
         "sScrollX": "200px", 
         "bPaginate": false 
        }); 

在.js文件中的一部分,它不会工作。可以在.js文件中运行这个脚本吗?如果是的话如何?

回答

1

试图运行使用的load

像这样回调JS代码:

placeholder.load("/Templates/Home/rpt.htm", function() { 
    $('#example').dataTable({ 
        "bProcessing": true, 
        "sAjaxSource": '/Home/GetData', 
        "sScrollY": "400px", 
        "sScrollX": "200px", 
        "bPaginate": false 
       }); 
}); 

欲了解更多信息,refer to the jQuery load docs

+0

它将引发我错误哎呦! 您正在查找的页面不存在。 :( – Naruto

+0

不能我们加载这个单独的像第一次加载网格,然后渲染数据? – Naruto

+0

你正在寻找的页面不存在=提供了错误的路径...尝试使用它,例如'Templates/Home/rpt .htm'或'。/ Templates/Home/rpt.htm'等 – Daniel