I have a function(with 200+ lines code). It could run when page loading or during some click events. Now how to decide if a function is run in page loading?
Here is a simple test code. also save in http://jsfiddle.net/EjcTk/ , Thanks.
<script>
jQuery(document).ready(function(){
function ABC() {
//many code here
if(someelse===undefined){
//if by click, do some code.
//if by page loading, do not run these code.
alert('ok');//check if it works.
}
}
$(document).ready(function() {
var someelse = 1;
ABC();
});
$('#click').click(function() {
ABC();
});
});
</script>
<div id="click">test</div>
Try this: