运行 jQuery 文件就绪函数第二次onclick?

Run jQuery document ready function a second time onclick?

对不起,我知道这可能是一个非常基本的问题。 我有一个文档就绪 jQuery 函数,它本身具有各种不同的函数。 此功能在每次页面加载时触发。

是否有可能在不重新加载页面的情况下再次运行点击此功能? 是否可以给函数命名,然后onclick再次触发?

例如:

$(document).ready(function() {
// doing a lot of stuff on DOM ready
});

$( "button" ).click(function() {
// do all the stuff again onclick without reloading the page
});

非常感谢您!

我认为您需要将常用功能放入一个函数中,并在加载和单击时调用它,如下所示:

$(document).ready(function() {
    // doing a lot of stuff on DOM ready
    DoSomething();  // Called on the Document Ready.


   $( "button" ).click(function() {
     // do all the stuff again onclick without reloading the page

      DoSomething();  // Called on the button click.
   });


});

function DoSomething() {
   // doing a lot of stuff
}

希望对您有所帮助。