用于传递变量的Javascript语法

时间:2011-10-03 12:49:48

标签: javascript flash

我仍在通过Javascript弄糊涂,我试图将变量 playnoyes 的内容传递给下面的长行代码,以决定是否自动播放Flash电影,但是这样做我在下面,结果的代码行有引号中的变量,因此代码不会按预期执行它。我的问题是,如何传递变量,以便生成的代码行没有变量值周围的引号。

非常感谢,并对这个问题的无聊感到抱歉。

var playnoyes='true';
var testtext = "<script type='text\/javascript'>AC_FL_RunContent ('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','320','height','220','id','HTIFLVPlayer','src','HTIFLVPlayer','flashvars','&MM_ComponentVersion=1&skinName=HTI_Skin&streamName=nigel&autoPlay=\""+playnoyes+"\"&autoRewind=true','quality','high','scale','noscale','name','HTIFLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','HTIFLVPlayer');<\/script>";
alert (testtext);

3 个答案:

答案 0 :(得分:2)

那是因为您明确添加了引号:

更改

nigel&autoPlay=\""+playnoyes+"\"&autoRewind=true'

 nigel&autoPlay=" + playnoyes + "&autoRewind=true'

答案 1 :(得分:1)

试试这个:

var playnoyes='true';
var testtext = "<script type='text\/javascript'>AC_FL_RunContent ('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','320','height','220','id','HTIFLVPlayer','src','HTIFLVPlayer','flashvars','&MM_ComponentVersion=1&skinName=HTI_Skin&streamName=nigel&autoPlay="+playnoyes+"&autoRewind=true','quality','high','scale','noscale','name','HTIFLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','HTIFLVPlayer');<\/script>";
alert (testtext);

答案 2 :(得分:1)

删除变量两侧的两个'\'',不是吗?