我正在尝试将Word变量从Wordpress自定义字段传递到javascript字符串中。 自定义字段包含Vimeo视频的ID号,它需要放置在单击时替换图像的字符串的中间。这是代码:
jQuery("#index-image").click(function(){
jQuery(this).replaceWith('<div id="video-container"><iframe id="videoframe" src="http://player.vimeo.com/video/"<?php echo $page_videos[$i]; ?>"color=ffffff&portrait=0&byline=0&title=0&autoplay=1&api=1&player_id=videoframe" frameborder="0" style="width: 100%;" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>');
为字符串创建一个警告作为变量返回带有视频ID号的正确字符串,但是浏览器只生成没有PHP变量的字符串。
不确定该怎么做。我已经尝试使用变量组装字符串并将其放入replaceWith函数中,但在任何地方都没有运气。
请帮忙。
答案 0 :(得分:1)
在我看来,变量正在src属性之外回显。
jQuery(this).replaceWith('<div id="video-container"><iframe id="videoframe" src="http://player.vimeo.com/video/<?php echo $page_videos[$i]; ?>&color=ffffff&portrait=0&byline=0&title=0&autoplay=1&api=1&player_id=videoframe" frameborder="0" style="width: 100%;" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>');