最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

inserting javascript variable into html output of .innerHTML = - Stack Overflow

programmeradmin3浏览0评论

I am trying to insert a variable passed to my function into the output of my .innerHTML = code but do not know how to properly insert it into the HTML output.

function playsong(song)
{
    parent.document.getElementById('player').innerHTML = '<object width="199" height="26"><param name="movie" value="audio_player_black.swf"><embed src="audio_player_black.swf?audio_file=upload/'[song]'&color=00000" width="199" height="26"></embed></object>';
}

I just get [song] in my HTML output rather than the value of [song]

Not sure how I need to do this properly

I am trying to insert a variable passed to my function into the output of my .innerHTML = code but do not know how to properly insert it into the HTML output.

function playsong(song)
{
    parent.document.getElementById('player').innerHTML = '<object width="199" height="26"><param name="movie" value="audio_player_black.swf"><embed src="audio_player_black.swf?audio_file=upload/'[song]'&color=00000" width="199" height="26"></embed></object>';
}

I just get [song] in my HTML output rather than the value of [song]

Not sure how I need to do this properly

Share Improve this question asked May 27, 2009 at 18:21 ianian 12.3k26 gold badges71 silver badges96 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 10

easy:

parent.document.getElementById('player').innerHTML = '<object width="199" height="26"><param name="movie" value="audio_player_black.swf"><embed src="audio_player_black.swf?audio_file=upload/'+song+'&color=00`000" width="199" height="26"></embed></object>';

just like concatenating any 2 + strings

Instead of:

[song]

use:

 +song+

In place of [song] use +song+. It's a concatenate function that will add the value.

发布评论

评论列表(0)

  1. 暂无评论