简体   繁体   中英

Function inside .on() not firing on first click

This block works every click:

$('body').on('click', '#searchButton', function(){
alert(studentInfo);
});

This one does not:

$('body').on('click', '#searchButton', function(){
var studentInfo = myFunction();
buildHtmlTables(studentInfo);
});

what do i need to do to get the function to call on the first click

它仍在触发,检查应该在单独的函数中执行的代码,在控制台上运行它,你会发现错误。

It should still be firing. You could add a console.log('search button on-click handler') and look at your browser's developer console. Even better, open the 'sources' tab of the dev tools and add a breakpoint at the line var studentInfo = myFunction(); so that you can step through the calls to see what's happening when you click.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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