oops - firefox中的ghost选项卡框

时间:2009-08-15 08:56:42

标签: php wordpress xhtml scripting

我很乐意将一些代码拼凑在一起,在我的(wordpress)页面上给我一个漂亮的标签框 - 2个标签;一个饲料和最近的评论。只有几天后我才注意到一个问题:Firefox显示2个选项卡框,一个在另一个下面,每个选项卡显示另一个选项卡。 IExplorer按预期显示单个功能选项卡。

有些善良的灵魂可以看一下明显故障的代码(?) - 我在php中保持完整性,但由于提要和评论显示正常,我认为可以忽略... [目前显示问题(使用Firefox)here]

<script>
  function diarytabs(newtab,oldtab) {
    if (document.getelementbyid)
    {
      document.getelementbyid(newtab).style.display = "inline";
      document.getelementbyid(oldtab).style.display = "none";
      return false;
    }
    else if (document.all)
    {
      document.all[oldtab].style.display = "none";
      document.all[newtab].style.display = "inline";
      return false;
    }
    else 
    {
      return true;
    }
  }
</script>

<div class="diary-tab" id="diary1">
  <ul class="tabs">
    <li class="each-tab" id="diary11">New Comments 
    <li id="diary12"><a onclick="return diarytabs('diary2','diary1')" href="#">Decanter News</a> 
  </ul>
  <?php 
  $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID,  comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 6");
  $numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
  if ( $comments || $numcomments ) :?>
    <ul class="tab-list">
    <?php 
    if ( $comments ) {
      foreach ($comments as $comment) {
      echo '<li>' . sprintf(__('%2$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>');
      edit_comment_link(__("Edit"), ' <small>(', ')</small>'); 
      echo '</li>';
      }
    }
    ?>
    </ul>
  <?php endif; ?>

  &nbsp;&nbsp;
  <?php if ( $numcomments ) : ?>
    <strong><?php echo sprintf(__('Comments in moderation (%s)'), number_format($numcomments) ); ?> &raquo;</strong>
  <?php endif; ?>
</div>
<div class="diary-tab" id="diary2">
  <ul class="tabs">
    <li id="diary21"><a onclick="return diarytabs('diary1','diary2')" href="#">New Comments</a></li>
    <li class="each-tab" id="diary22">Decanter News
  </ul>
  <?php
    require_once (ABSPATH . WPINC . '/rss-functions.php');
    // here's where to insert the feed address
    $rss = @fetch_rss('http://www.decanter.com/feeds/rss/news.xml');
    if ( isset($rss->items) && 0 != count($rss->items) ) {
  ?>
    <ul class="tab-list">
      <?php
      // here's (6) where to set the number of headlines
      $rss->items = array_slice($rss->items, 0, 6);
      foreach ($rss->items as $item ) {
      ?>
        <li>
        <a href='<?php echo wp_filter_kses($item['link']); ?>'><?php echo wp_specialchars($item['title']); ?></a>
        </li>
      <?php } ?>
    </ul>
  <?php } ?>
</div>

1 个答案:

答案 0 :(得分:0)

Javascript函数名称区分大小写。

document.getElementById不是document.getelementbyid

alert(typeof document.getelementbyid); // undefined
alert(typeof document.getElementById); // function

// you want to use this:
    if (document.getElementById)
    {
      document.getElementById(newtab).style.display = "inline";
      document.getElementById(oldtab).style.display = "none";
      return false;
    }