[英]Loading script from .js file
我正在尝试从.js文件加载.htm模板。 但是.htm文件中存在一个脚本,该脚本在加载模板且一切顺利时会触发。
此处的模板外观。 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文件中运行此脚本? 如果是这样怎么办?
尝试使用load
的回调运行该js代码
像这样 :
placeholder.load("/Templates/Home/rpt.htm", function() {
$('#example').dataTable({
"bProcessing": true,
"sAjaxSource": '/Home/GetData',
"sScrollY": "400px",
"sScrollX": "200px",
"bPaginate": false
});
});
有关更多信息, 请参考jQuery load
docs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.