0

カレンダーと「Today in Weather History」情報を含む html ファイルがあります。誰かがカレンダーの特定の日をクリックするまで、すべての気象履歴を非表示にして、その日の履歴のみを表示したいと考えています。

毎日の天気情報は非表示になっていますが、暦日をクリックしても特定の日は表示されません。私はこれについてすべて間違っていると思います。それについてのより良い方法をいただければ幸いです。

暦日リンク:

<td align="right"><a id="c0408" href="#"> 8</a></td>

気象履歴:

<div id="allhistory">
  <div id="hc0408" style="display:none">
    <ul>
      <li class="dateheader">April 8, 2007</li>
      <li>The Savannah Airport drops to 28 degrees, its lowest April 
          temperature.</li>
      <li class="dateheader">April 8, 2007</li>
      <li>Summerville has their coldest April temperature, when the mercury 
          falls to 27 degrees.</li>
    </ul>
  </div>

  <div id="hc0409" style="display:none">
    <ul>
      <li class="dateheader">April 9, 2011</li>
      <li>Severe thunderstorms impact Berkeley County in South Carolina, 
          with hail as large as tennis balls (2.5 inches) and winds as 
          high as 64 mph.</li>
    </ul> <!-- 0409 -->
  </div>
</div> <!-- all history div -->

jQuery コード:

<script>
  $(document).ready(function() { 
    $('#calendar a').click(function() {
      var dateid = $(this).attr('id');
      var selection = "div#h"+dateid;
      $("selection").show();
     })
  });
</script>
4

3 に答える 3

0

これを試して:

$(document).ready(function() { 
    $('#calendar a').click(function(e) {
      e.preventDefault();
      $('#allhistory [id^="h"]').hide();
      $('#h'+$(this).attr('id')).css('display','inline-block');
     })
});
于 2013-04-09T17:24:03.747 に答える
0

ID を連結し、それぞれの jquery オブジェクトを表示します

これを試して

$('#calendar a').click(function(e) {
   e.preventDefault();  //to prevent the default behaviour of a
  var dateid = $(this).attr('id');
  var selection = $("#h"+dateid); //assign selection as jquery object
  selection.show(); //show it
  .....
于 2013-04-09T17:06:45.587 に答える
0

$("selection").show();

これはあなたの問題です。文字列「selection」をセレクターとして提供しています。変数を提供したい。このような:

$(selection).show();

于 2013-04-09T17:07:37.627 に答える