动态调用php whit参数中的javascript函数
问题描述:
我正在动态创建视频列表。在这里,我动态添加了javascript onclick事件;但是,我必须调用一个从php获取参数的javascript函数。
这是我的PHP代码:
I am creating a Video List dynamically. Here, I have added javascript onclick event dynamically; But, I have to call a javascript function which get parameter from php.
here is my php code:
while (($file = readdir($dh)) !== false) {
if ($file == ".") {
echo '..<br>';
} elseif ($file == "..") {
echo '..<br>';
} else {
echo ''. $file . '<br>';
echo '<br><video id="button_' . $i . '" autobuffer preload="auto" style="width:200px;height:300px" src="videos/' . $file . '" önclick=' . $ch . 'add(this.src)' . $ch . '></video>';
//echo '<br><input type="button" id="button_' . $i . '" class="mybuttons" value="Play" name="videos/' . $file . '" onclick=' . $ch . 'add(this.name)' . $ch . '/>';
$i = $i + 1;
}
}
我的javascript功能是:
And my javascript function is:
function playVideo2() {
var starttime = 2; // start at 2 seconds
var endtime = 6; // stop at 4 seconds
var b = <?php echo 'button_3'; ?>;
var c = "'" + b + "'";
var video = document.getElementById(c);
video.play();
setTimeout(function() {
video.pause();
}, 125);
//handler should be bound first
}
并且:
And :
function playVideo() {
var starttime = 2; // start at 2 seconds
var endtime = 6; // stop at 4 seconds
var video = document.getElementById('v0');
video.play();
setTimeout(function() {
video.pause();
}, 125);
//handler should be bound first
}
在函数playVideo2()中,我在那里试过PHP。当我从html调用此函数时,这不起作用。我的HTML代码:
In function playVideo2(), I have tried PHP there. This is not working while I have call this function from html. My html code:
<body önload="playVideo();
playVideo2();">
<p id="time"></p>
<video id="v0" controls tabindex="0" autobuffer preload>
<source type="video/webm; codecs="vp8, vorbis"" src="videos/Wildlife.webm"></source>
<p>Sorry, your browser does not support the <video> element.</p>
</video>
答
file = readdir(
file = readdir(
dh))!== false){
if (
dh)) !== false) { if (
file == 。){
echo ' ..< br>';
} elseif(
file == ".") { echo '..<br>'; } elseif (