I am facing a error in javascript....
when the javascript function calling it is not working but if i set a alert('someting');
within the function then the script is running but if i开发者_开发问答 comment off the alert within the script,
is not working. what is the solution.......
put you code in try.. catch block and check is there any exception
try
{
//Run some code here
}
catch(err)
{
//Handle errors here
alert(err);
}
Try putting your code in load event:
window.onload = function(){
// your code...
};
Or put your js code at the end of the page.
if you're running with firefox, you won't know whether error occur in this function or not.
When you include the alert your most likely giving elements on the page you are loading time to appear which are probably required for you JS to actually run.
You could try using:
window.onload = function(){
//drop some code in here
}
or you could use jquery and wrap your code into a document.ready function like this:
$(document).ready(function() {
// put all your jQuery goodness in here.
});
You will need to load the latest version of jquery onto your page if you were to you this method.
精彩评论