Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery将变量传递到分配给元素的html中_Jquery - Fatal编程技术网

如何使用jquery将变量传递到分配给元素的html中

如何使用jquery将变量传递到分配给元素的html中,jquery,Jquery,我正在尝试这样做: $('#player-container').html('<div id="film-player" class="flowplayer play-button is-splash" style="background:#777 url(myVariable) no-repeat;">'); $(“#播放器容器”).html(“”); html没有显示,因为它不在这里的代码块中。基本上,我试图在动态分配给元素的html中嵌套这样一个变量:style等于bac

我正在尝试这样做:

$('#player-container').html('<div id="film-player" class="flowplayer play-button is-splash"  style="background:#777 url(myVariable) no-repeat;">');
$(“#播放器容器”).html(“”);

html没有显示,因为它不在这里的代码块中。基本上,我试图在动态分配给元素的html中嵌套这样一个变量:style等于background url(myVariable)

由于字符串是以单引号开头的,因此您可以再次使用
'
+
如下连接:
url(“+myVariable+”)

因此,您的代码应该是:

$('#player-container').html('<div id="film-player" class="flowplayer play-button is-splash"   style="background:#777 url('+myVariable+') no-repeat;">');
$(“#播放器容器”).html(“”);

有关连接运算符(javascript)的详细信息,请参见

,因为您使用单引号开始字符串,所以再次使用
'
+
进行如下连接:
url(“+myVariable+”)

因此,您的代码应该是:

$('#player-container').html('<div id="film-player" class="flowplayer play-button is-splash"   style="background:#777 url('+myVariable+') no-repeat;">');
$(“#播放器容器”).html(“”);

更多关于连接运算符(javascript)的信息,请访问

谢谢,我只是自己做的,而你回答说,非常好@温迪,太好了!或许您可以单击以接受答案;)哎呀,我以为我做到了!投了赞成票,这就是当你点击太快时会发生的情况…谢谢,我只是自己做的,而你回答说,很好@温迪,太好了!或许您可以单击以接受答案;)哎呀,我以为我做到了!投了赞成票,这就是当你点击太快时发生的事情。。。