动态调用php whit参数中的javascript函数 [英] dynamically call javascript function in php whit parameters

查看:62
本文介绍了动态调用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 (


这篇关于动态调用php whit参数中的javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆