开发者

Javascript id question

I have a beginner question. I have a shoutbox, an A开发者_开发百科jax shoutbox.

I made a form where i can update the users depending on them being a DJ or not.

If that option is selected then a small image appears after the user's name.

Is working but I can't make it work but my problem is, that if I set it on my profile, it adds the image to everybody's name.

Here is my code:

var radios = document.getElementById("radios"); 
   if(radios.innerHTML == 'yes') {
   radios = "<img src='http://www.site/pic/radios.gif'>";
   }

My question is: How to insert the current user's id in this if statement?


In the code sample you've included, there appears to be an error.

With this line of code:

var radios = document.getElementById("radios"); 

you get the DOM object that has an id="radios". Then, you try to set that same variable to be a piece of HTML:

radios = "<img src='http://site/pic/radios.gif'>";

That won't accomplish anything other than setting a variable that you were previously using to store a DOM object to now be a string. That line of code does not modify the DOM in any way. Did you mean to write it this way?

radios.innerHTML = "<img src='http://site/pic/radios.gif'>";
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜