这是我的代码: -
<?php
$sql = "SELECT * FROM era_videos ORDER BY video_id";
$sqlex = mysqli_query($db,$sql);
$m = 1;
while($result = mysqli_fetch_assoc($sqlex))
{
?>
<div class="slide" current_id="<?php echo $m;?>" style="width:300px !important; height:200px !important;">
<object class="youtube" id="videoid<?php echo $m;?>" width="300" height="200"><param name="movie" value="https://www.youtube.com/v/<?php echo $result['urlname'];?>"version=3&hl=en_US&rel=0"> </param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/<?php echo $result['urlname'];?>"version=3&hl=en_US&rel=0" type="application/x-shockwave-flash" width="300" height="200" allowscriptaccess="always" allowfullscreen="true"></embed></object>
</div>
<?php
$m++;
}
?>
jQuery代码: -
jQuery('#iCarouselNext').click(function()
{
var current_id = parseInt($('.current').attr('current_id'));
var previous_id = current_id - 1;
$('#videoid'+previous_id).stopVideo();
});
但它会引发错误 - Uncaught TypeError: Object [object Object] has no method 'stopVideo'
我找到了这个但没有解决方案Stop a youtube video with jquery?
提前致谢
答案 0 :(得分:0)
使用
$('#videoid'+previous_id).get(0).stopVideo();
或者
$('#videoid'+previous_id)[0].stopVideo();
获取current_id的逻辑也是错误的
var current_id = parseInt($('.current').attr('current_id'));
这将始终提供第一个元素的ID。