我的问题是双重的第一,下面的代码包含两个班.fbs和.tws如果删除.fbs脚本交易平台sript作品,反之亦然,但他们不工作一起。我WordPress的循环中的工作,我的HTML/PHP看起来是这样的: (有明显更多,但是这是问题的一部分)jQuery的隐藏无法正常工作
HTML:
<div class="social-team-list">
<ul>
<?php echo '<li class="fbs'.$i.'">'?><a href="<?php the_field('facebook_url'); ?>">
<img src="/wp-content/images/fb-team.png"></a></li>
<?php echo '<li class="tws'.$i.'">'?><a href="<?php the_field('twitter_url'); ?>">
<img src="/wp-content/images/tw-team.png"></a></li>
</ul>
</div>
输出如下像这样:
<div class="social-team-list">
<ul>
<li class="fbs1">
<a href="https://www.facebook.com/whatever"><img src="/wp-content/images/fb-team.png"></a>
</li>
<li class="tws1">
<a href="https://twitter.com/whatever"><img src="/wp-content/images/tw-team.png"></a>
</li>
</ul>
</div>
<div class="social-team-list">
<ul>
<li class="fbs2">
<a href="https://www.facebook.com/whatever"><img src="/wp-content/images/fb-team.png"></a>
</li>
<li class="tws2">
<a href="https://twitter.com/whatever"><img src="/wp-content/images/tw-team.png"></a>
</li>
</ul>
</div>
的jQuery:
<script>
$(document).ready(function(){
if ($(".fbs1").html().length < 58) {
$('.fbs1').hide();
}
if ($(".fbs2").html().length < 58) {
$('.fbs2').hide();
}
if ($(".fbs3").html().length < 58) {
$('.fbs3').hide();
}
if ($(".fbs4").html().length < 58) {
$('.fbs4').hide();
}
if ($(".tws1").html().length < 58) {
$('.tws1').hide();
}
if ($(".tws2").html().length < 58) {
$('.tws2').hide();
}
if ($(".tws3").html().length < 58) {
$('.tws3').hide();
}
if ($(".tws4").html().length < 58) {
$('.tws4').hide();
}
});
</script>
我的问题的第二部分是,假设我可以得到这个工作,是否有更有效的方法来编写这个脚本?
我敢肯定我做错了,因为我的jQuery技能不是很好。
有什么目的'如果($()HTML()。长度<58)'?你是否试图检查'<?php the_field('facebook_url'); ?>是空的? –