如何在单击按钮时加载div?

单击按钮时,我将在html div标签中显示Flexigrid。Flexigrid的功能将在Javascript函数中,所以我用onclick添加了一个图像标签,以调用一个名为d f_reload的函数,该函数将加载flexigrid函数。 第一次加载时有用,但第二次单击它却不会再次加载网格。

      <script type="text/javascript">

        function loadFlexiGrid(){
                 //here flexigrid content 
                     $("#flex1").flexigrid{{
                        //...........}}
         }  

        function eventhandler() {
                $("#flex").html(function() {    //this function used to reload grid but it is not called when click second time on the button
            return "<div id='flex1'></div>";});

        javascript:loadGrid();
        }
    </script>

<input type="image" class="btn" id="sub" src="<?=base_url();?>images/rbtnsave.gif"        
                                    onclick="eventhandler();"/>
    <div id="flex"><div id="flex1"></div></div>
    </div>

这里flecigrid的flex1 id和flex是div的id。

第一次单击按钮时,它会显示网格,但第二次不行。

use click() function ..

$("#flex").click(function()

When the eventHandler is executed, the nested function in $('#flex').html() is declared, but not executed. Is there a particular reason why you put it there?

Otherwise, try replacing it with:

    function eventhandler() 
    {
        $("#flex").html("<div id='flex1'></div>");
        javascript:loadGrid();
    }

The first time it works fine, since you've put <div id="flex1"></div> manually in your HTML.

Besides, are you sure javascript:loadGrid() is correct? Try removing the javascript: part. And - if referring to function loadFlexiGrid(), call it loadFlexiGrid();, not loadGrid();.