Exploring Javascript (and coming from the Java world). I have the follow开发者_Go百科ing line of code in a script:
if (jQuery) {
document.getElementById("BOTTOM_MID").innerHTML
= "JQuery Loaded - " + getTime();
}
but it does not work. BOTTOM_MID
is not initialized. Yet, the following works:
if (jQuery) {
document.getElementById("BOTTOM_MID").innerHTML
= "JQuery Loaded";
}
Doesn't Javascript understand string construction by concatenation? If yes, how should I proceed?
getTime()
is a method of the Date
object. Try this:
if (jQuery) {
document.getElementById("BOTTOM_MID").innerHTML
= "JQuery Loaded - " + new Date().getTime();
}
Since you're using jQuery, I also suggest that you use jQuery's ready()
handler and selectors:
$(document).ready(function() {
$("#BOTTOM_MID").html("JQuery Loaded - " + new Date().getTime());
});
Here's a working fiddle.
Your code looks fine, try to run this on your chrome developer tools or firebug's console, in this web page:
document.getElementById("notify-container").innerHTML = "JQuery Loaded - " + "hello"
It will work, indeed.
Perhaps you don't have getTime()
defined? It's not a standard javascript function BTW
精彩评论