Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在活动引导转盘幻灯片中以iframe元素为目标,并向SRC属性添加哈希?_Javascript_Jquery_Twitter Bootstrap_Iframe_Append - Fatal编程技术网

Javascript 在活动引导转盘幻灯片中以iframe元素为目标,并向SRC属性添加哈希?

Javascript 在活动引导转盘幻灯片中以iframe元素为目标,并向SRC属性添加哈希?,javascript,jquery,twitter-bootstrap,iframe,append,Javascript,Jquery,Twitter Bootstrap,Iframe,Append,我在我的页面上的中嵌入了iframe元素。这是我的HTML: <div id="carousel1" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> <li data-target="#carousel1" data-slide-to="0" class="active"></li> <li data-target="#carousel

我在我的页面上的中嵌入了iframe元素。这是我的HTML:

<div id="carousel1" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel1" data-slide-to="0" class="active"></li>
<li data-target="#carousel1" data-slide-to="1"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<iframe src="http://iframe.url/index.html" width="160" height="600" frameborder="0"></iframe>
</div>
<div class="item">
<iframe src="http://another.iframe.url/index.html" width="300" height="600" frameborder="0"></iframe>
</div>
</div>
<a class="left carousel-control" href="#carousel1" role="button" data-slide="prev">
<span class="icon-prev" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel1" role="button" data-slide="next">
<span class="icon-next" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
编辑我一直在试图想出一个解决办法。这仍然不起作用,但我认为它越来越接近我想要的:

// Trigger Active Slide to Play
$('.carousel').on('slid.bs.carousel', function() {
var activeItem = $(this).find('.active.item');
if (parent().is(activeItem)) {
    $(this).find('iframe').attr('src', function() {
        return $(this).attr('src') + "#play"
    })
    }
});

有一个工作代码:

    $('.carousel').on('slide.bs.carousel', function () {
      $(this).find('.active.item').attr('src', function(){
        return $(this).attr('src') + "#play"
      })
     });
您在“slide.bs.carousel”中有一个输入错误,也没有必要尝试使用事件,否则逻辑就可以了


确保在播放处于非活动状态时删除播放。

这似乎将逻辑添加到iframe元素上方的div中。脚本运行时会发生这种情况:iframe元素是此div的子元素。如何更改此脚本以子iframe元素为目标,而不是.active.item?$'.carousel'。在'slide.bs.carousel'上,函数{$This.find'.active.item'.children'iframe'.attr'src',函数{return This.attr'src'+play} }; 将子项的iframe添加到目标iframe。
    $('.carousel').on('slide.bs.carousel', function () {
      $(this).find('.active.item').attr('src', function(){
        return $(this).attr('src') + "#play"
      })
     });