0

.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ファイルで実行することは可能ですか?もしそうなら、どのように?

4

1 に答える 1

1

のコールバックを使用してその js コードを実行してみてくださいload

このような :

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

詳細については、jQueryloadドキュメントを参照してください。

于 2013-01-17T10:51:31.833 に答える