Why doesn't any javascript function written inside document.ready be directly called from an event in jsp?
Eg:
$(document).ready(function(){
function abc()
{
//Some stuff here
}
});
From something like:
<input id="a" type="button" onclick="abc();">
Because it's not available in the global scope. Any function defined within the anonymous function you pass as an argument to $.ready()
is only available within that function.
To achieve what you want to do you need something like:
$(document).ready(function(){
function abc() {}
$('#a').on('click',abc);
});
For more information on function scope see this MDN article
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.