将PHP变量传递给jQuery函数 [英] Passing PHP Variable Into jQuery Function
问题描述
我正在尝试为我的网站实现jQuery Flare视频插件..有一个下拉菜单,用户必须从下拉菜单中选择年份,单击提交"按钮时,应在屏幕上显示视频.我有一个数据库,该数据库从数据库中获取视频的路径,即$row['videoName']
.
我的问题是如何在jQuery函数中传递PHP变量.在插件中给出的示例中,视频的完整路径在jQuery函数的src
属性中给出.我正在尝试通过将PHP变量传递到其中来使src
动态.
I'm trying to implement jQuery Flare Video Plugin for my website.. There's a dropdown menu which the user must choose a year from, when the submit button is clicked, a video is meant to show on the screen. I have a database that grabs the path to the video from the database i.e $row['videoName']
.
My question is how can I pass PHP variables in jQuery function.. In the example given in the plugin a full path to the video was given insrc
attribute of jQuery function. I'm trying to make the src
dynamic by passing the PHP Variable into it.
我没有收到任何错误,并且包含视频的div出现在屏幕上,但是视频没有显示.
I'm not getting any error, and the div containing the video appears on the screen, but the video does not show.
谢谢.
jQuery(function($){
fv = $("#video").flareVideo();
fv.load([
{
src: '$row['videoName']',
type: 'video/mp4'
}
]);
})
</script>
推荐答案
要访问PHP变量,必须将代码括在PHP括号中,如下所示:
To access the PHP variable you must enclose the code in PHP brackets like so:
jQuery(function($){
fv = $("#video").flareVideo();
fv.load([
{
src: "<?php echo $row['videoName']; ?>",
type: 'video/mp4'
}
]);
})
</script>
这还必须与创建PHP变量的页面位于同一页上,以允许访问.
This must also be on the same page as the PHP variable is created to allow access.
这篇关于将PHP变量传递给jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!