快速问题。如果我想一次性清除多个具有相同类的div,是否有jQuery的快捷方式可以做到这一点?我尝试了$('.clearit').empty();
,但似乎根本不起作用(没有一个具有该类的div被清除)。我是不是做错了,还是这个方法就不起作用?让我知道,我还尝试了$('.clearit').html('');
。此外,我还有其他代码与它一起在jquery中运行,其他所有内容都按预期运行。我调试了代码,似乎函数成功执行并继续进行,但div内容未被清除。以下是div的示例:
<center><div class="clearit" id="container2">Loading the player ...</div></center>
</li>
<li>
<center><div class="clearit" id="container3">Loading the player ...</div></center>
</li>
<li>
<center><div class="clearit" id="container4">Loading the player ...</div></center>
这里是一个处理程序的代码。请注意,除了 $('.clearit').html('');
之外,其中的所有内容都有效。
$('.thumbNav li a').click(function(){
$('.clearit').html('');
var str = $(this).html();
var pattern = /[0-9]+/g;
var matches = str.match(pattern);
var myInteger = parseInt(matches);
//variable for player
var container = "container"+myInteger;
var what = 'skill'+myInteger;
var location = "https://aliahealthcare.com/videofetcher.php?id=skill"+myInteger;
player(container,what,location);
$('#'+what).attr('selected', 'selected');
});
感谢任何还在帮助我的人!我已经修改了网站,所以您不再需要登录即可进入,这样您就可以亲自看到它的运行情况。请使用上面的代码作为查找JavaScript的参考。(它全部位于vid.php中)谢谢
https://aliahealthcare.com/vid.php
我刚刚发现了一些有趣的事情。上面的li是在id为slider的ul中的一部分。当我执行$('#slider').html('');
或$('#slider').empty();
时,它可以工作,但会清除所有的div,因此加载在这些div中的播放器不会加载。我所需要做的只是清除播放器,这样就不会同时运行多个播放器。