JavaScript not working in FF 5
Following line doesn't work in FF 5.
<a href="javascript:func1(upDiv);">Resend Pin</a>
<div id="upDiv">ASDFGHJKL</div>
JS function
function开发者_如何学Python func1(windowname) {
alert(windowname);
}
It works in Google Chrome and even in IE8.
function func1(windowname) {
alert(document.getElementById(windowname).innerHTML);
}
IE and Chrome have the (bad) habit of creating a global variable for each element with an ID which refers to that element.
Pass a string and use getElementById
instead:
<a href="javascript:func1('upDiv');">Resend Pin</a>
function func1(windowname) {
alert(document.getElementById(windowname));
}
Also, don't use the javascript:
pseudo protocol. Either refer to a proper location so that it works if JS is disabled or use a button, and attach an event handler for the click
event. E.g.
<button onclick="func1('upDiv');">Resend Pin</button>
You can style the button as a link if you really want to.
Mhmm works for me when you have a var upDiv defined in the global namespace: http://jsfiddle.net/vNnvg/
Edit: Ahh, read your edit question. In IE all element ids come member of the global name space, so if you have an element with id "myId", you can get it by simply call window.myId or just myId in JavaScript. this will not work in Firefox. Btw, I wonder that this works in Chrome.
精彩评论