再次运行onclick运行jQuery文档就绪功能?

问题描述 投票:0回答:1

对不起,我知道这可能是一个非常基本的问题。我有一个文档就绪的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
});

非常感谢!

jquery onclick document-ready
1个回答
0
投票

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

$(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
}

希望有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.