繁体   English   中英

重新加载JQuery表后JavaScript无法执行

[英]JavaScript not executing after JQuery table reload

我有一个为我重新加载表的函数,但是当我单击以重新加载表时,该函数不会在其中执行JavaScript。 它确实刷新。 我只是暂时使用h3来单击,因为这很容易。

<script>
        function RefreshTable()
         {
            $( "#calenderTable" ).load( "my-page.html #calenderTable" );
          }

        $(document).ready(function()
        {
          $("h3").click(function()
          {
            RefreshTable();
          });

        });
</script>

HTML是

  <h3>Refresh Table</h3>

                                     <table class="table" id="calenderTable">

                                        <tr>
                                            <th  scope="col">House</th>
                                            <th scope="col">Monday <br><script type="text/javascript">document.write("Hello World");</script></th>
                                            <th scope="col">Tuesday <br><script type="text/javascript">document.write(getDate(2));</script></th>
                                            <th scope="col">Wednsday <br><script type="text/javascript">document.write(getDate(3));</script></th>
                                            <th scope="col">Thursday <br><script type="text/javascript">document.write(getDate(4));</script></th>
                                            <th scope="col">Friday <br> <script type="text/javascript">document.write(getDate(5));</script></th>
                                        </tr>

                                    <tbody>
                                        <tr>
                                            <td class="cal"><a href="#"> 1 </a></td>
                                            <td ></td>
                                            <td ></td>
                                            <td ></td>
                                            <td ></td>
                                            <td></td>
                                        </tr>
                                    </tbody>
                                </table>

因此,第一次加载页面时,它会显示“ hello world”,但是当我单击刷新时,它将不再显示。 我只是在这个示例中使用hello world,我真的希望getDate函数执行并在表中显示正确的日期。

如果我明白

<script>
    function refreshTable() {
        $.ajax({
            url: 'my-page.html',
            type: 'GET',
            success: function (html) {
                $("#calenderTable").html($(html).find("#calenderTable").html());
            }
        });
    }

    $(document).ready(function () {
        $("h3").on('click', function () {
            refreshTable();
        });

    });
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM