简体   繁体   English

将PHP变量传递到Javascript字符串中以进行嵌入式Vimeo链接

[英]Passing PHP variable into Javascript String for embedded Vimeo Link

I'm trying to pass a PHP variable from Wordpress custom field into a javascript string. 我试图将PHP变量从Wordpress自定义字段传递到javascript字符串中。 The custom field contains the ID number for a Vimeo video and it needs to be place in the middle the the string thats replacing an image on click. 自定义字段包含Vimeo视频的ID号,需要将其放置在替换单击图片的字符串的中间。 Here's the code: 这是代码:

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>');

Creating an alert for the string as a variable returns the correct string with the ID number of the video, however the browser only generates the string without the PHP variable. 将字符串作为变量创建警报会返回带有视频ID号的正确字符串,但是浏览器只会生成不带PHP变量的字符串。

Not sure what to do. 不知道该怎么办。 I've tried assembling the string using variables and putting it into the replaceWith function but am having no luck anywhere. 我试过使用变量组装字符串并将其放入replaceWith函数中,但是在任何地方都没有运气。

Please help. 请帮忙。

在我看来,该变量正在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>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM