开发者

Changing Z-Index onclick

JavaScript noob here. I'm working on a开发者_开发百科 website and I'm trying to change the z-index of a set of frames using buttons. I can't quite get it to work.

So far this is what I have.

function changeZIndex(i,id) {
  document.getElementById(id).style.zIndex=i;
}

And in the body

<A HREF="#" onclick='changeZIndex(1,'aboutus')'><IMG NAME="one" SRC="button1.bmp"></A>
<A HREF="#" onclick='changeZIndex(1,'contactus')'><IMG NAME="two" SRC="button2.bmp"></A>

Yeah, I realize this is probably the stupidest question ever and the answer is really obvious. This is my first time writing JavaScript though, so please go easy on me! :3


Make sure your quotes are escaped correctly. try:

<a href="#" onclick="changeZIndex(1,'aboutus')"><img name="one" src="button1.bmp"></a>
<a href="#" onclick="changeZIndex(1,'contactus')"><img name="two" src="button2.bmp"></a>

note the double quotes around the onclick


Your quotation marks are wrong - look at the syntax highlighting:

<A HREF="#" onclick='changeZIndex(1,'aboutus')'><IMG NAME="one" SRC="button1.bmp"></A>
<A HREF="#" onclick='changeZIndex(1,'contactus')'><IMG NAME="two" SRC="button2.bmp"></A>

This is how you could do it:

<A HREF="#" onclick="changeZIndex(1,'aboutus')"><IMG NAME="one" SRC="button1.bmp"></A>
<A HREF="#" onclick="changeZIndex(1,'contactus')"><IMG NAME="two" SRC="button2.bmp"></A>


look at your quotes,
then if you change zindex for 'aboutus' to 1, don't forget to change zindex for 'contactus' to 0.
otherwise if you change zindex for 'contactus' to 1, don't forget to change zindex for 'aboutus' to 0.

<A HREF="#" onclick="changeZIndex(1,'aboutus');changeZIndex(0,'contactus');"><IMG NAME="one" SRC="button1.bmp"></A>
<A HREF="#" onclick="changeZIndex(1,'contactus');changeZIndex(0,'aboutus');"><IMG NAME="two" SRC="button2.bmp"></A>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜