【问题标题】:Loop through a jQuery .post function multiple times多次循环 jQuery .post 函数
【发布时间】:2011-03-10 02:15:38
【问题描述】:

所以我在我的 wordpress 网站上使用 jsplayer HTML5 播放器,以及在下一篇文章中加载的一些自定义脚本,并在视频完成后替换旧内容:

    $(document).ready(function(){
        $(".video-js").bind('ended', function(){
            var sStr = "<?php echo get_permalink(get_adjacent_post(true,'',true)); ?>";
            var adj_numb = "<?php 
                            $adj = get_adjacent_post(true,'',true); 
                            $numb = $adj->ID;
                            echo $numb
                            ?>";
            var cur_numb = "<?php echo $post->ID; ?>";
            $.post(sStr, function(data) {
                var content = $( data ).find( '#post-' + adj_numb);
                $( "#post-" + cur_numb ).html( content );
                var vid = VideoJS.setup( "vid" );
                vid.play();
            });
        });
    });

这非常有效,仅适用于一个视频。它在下一个视频中加载并播放,但在第二个视频播放后它就停止了。我认为这意味着我必须“重置”所有变量并从脚本的开头重新开始,并且由于 $(document).ready(function() 而不是这样做的,因为它已经全部加载这一点。

是否有一种标准方法可以再次循环遍历此脚本,并在其运行一次后重新设置所有变量?

谢谢!

编辑:渲染的 JS:

    $(document).ready(function(){
        $(".video-js").live('ended', function(){
            var sStr = "http://www.theloniousfilms.com/zachmath/volkswagon/";
            var adj_numb = "94";
            var cur_numb = "96";
            $.post(sStr, function(data) {
                var content = $( data ).find( '#post-' + adj_numb);
                $( "#post-" + cur_numb ).html( content );
                var vid = VideoJS.setup( "vid" );
                vid.play();
            });
        });
    });

HTML:

<div class="post-96 post type-post status-publish format-standard hentry category-zachmath" id="post-96">
            <h2 id="director">Zach Math</h2>

            <h2 id="post_title">Orkin - 
                <span id="post_name">

                "Hot Tub"
                 </span>
                 <span id="home"><a href="http://www.theloniousfilms.com/">HOME</a></span>

                <div class="entry">

                    <div class="video-js-box">
        <!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --><br />
        <video id="vid" class="video-js" width="640" height="360" preload autoplay poster="http://www.theloniousfilms.com/wp-content/uploads/2011/03/poster.jpg"><br />
          <source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /><br />

          <source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.ogv" type='video/ogg; codecs="theora, vorbis"' /><br />
          <!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --><br />
          <object class="vjs-flash-fallback" width="640" height="360" type="application/x-shockwave-flash"<br />
            data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"><param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /><param name="allowfullscreen" value="true" /><param name="flashvars" value='config={"playlist":["http://www.theloniousfilms.com/wp-content/uploads/2011/03/poster.jpg", {"url": "http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v","autoPlay":true,"autoBuffering":true}]}' /><!-- Image Fallback. Typically the same as the poster image. --><br />
          </object><br />
        </video>
      </div>

【问题讨论】:

  • 能否也提供相应的HTML。

标签: php javascript jquery wordpress html


【解决方案1】:

看起来 HTML 正在被重写

$( "#post-" + cur_numb ).html( content );

改变

$(".video-js").bind('ended', function(){

$(".video-js").live('ended', function(){

这应该会照顾它。

还有,改变

$( "#post-" + cur_numb ).html( content );

$( "#post-" + cur_numb ).replaceWith( content );

【讨论】:

  • 你说得对,应该可以。但它没有。相反,它甚至不推进一个视频,根本没有打电话。可能跟jsvideo有关
  • 更新了帖子,又做了一个改动。
【解决方案2】:

我最终只是将所有帖子 url 拉到一个数组中,然后遍历它们中的每一个,一旦上一个视频播放完毕,就移动到数组中的下一个项目。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2016-02-04
    • 1970-01-01
    • 2019-06-02
    • 2019-08-29
    • 2016-12-21
    • 2012-01-09
    相关资源
    最近更新 更多