0

ドロップダウンからURLを介して選択したデータを、別のファンシーボックスを開くページ上のいくつかのリンクに送信することにしました。しかし、それは一度だけ機能します。

正しいデータを送信するファンシーボックスを開きますが、ファンシーボックスを閉じると(ファンシーボックスのページだけが更新されないことを意味します)、ドロップダウンの値を変更してファンシーボックスを再度開くと、送信された値は変更されませんでしたそして、私は最初の送信値にこだわっています。

なぜうまくいかないのか教えてください。私はjqueryが初めてです。ありがとう。

$the_event = mysql_query("SELECT `event_id`, `name` FROM `event` ORDER BY event_id ASC");

イベントのドロップダウンメニュー

 echo '<select name="<?php$the_event?>" style="width: 150px">';
while( list($event_id, $event_name) = mysql_fetch_row($the_event) )
{

echo '<option value="'.$event_id.'">'.$event_name.'</option>';

}

echo '</select>';

?>
</div>

ファンシーボックスで各スポーツの異なる統計を開く、イベントのさまざまなスポーツのメニューギャラリー

<nav>

<a class="fancybox" rel="gallery_hurdling" data-fancybox-type="iframe" href="http://www.wattsports.co.uk/wp-content/themes/canvas/H1.php" data-fancybox-group="gallery_hurdling"  tabindex="1" title="hurdling" alt="sport 1"   ><img src="http://www.wattsports.co.uk/css/hurdling.png" alt="sport 1"  /></a>

<div class="hidden">

<a class="fancybox" rel="gallery_hurdling" data-fancybox-type="iframe" href="http://www.wattsports.co.uk/wp-content/themes/canvas/H2.php" data-fancybox-group="gallery_hurdling" title="hurdling"  ></a>

</div>

<a class="fancybox"  data-fancybox-type="iframe"  data-fancybox-group="gallery_wattball" href="http://www.wattsports.co.uk/wp-content/themes/canvas/template-statistics_details2.php"  tabindex="2" title="wattball" alt="sport 2"   ><img src="http://www.wattsports.co.uk/css/wattball.png" alt="sport 2"  />         </a>

<div class="hidden">

<a class="fancybox"  data-fancybox-type="iframe"  data-fancybox-group="gallery_wattball" href="http://www.wattsports.co.uk/wp-content/themes/canvas/template-statistics_details1.php" title="wattball"  > </a>

<a class="fancybox"   data-fancybox-type="iframe"  data-fancybox-group="gallery_wattball" href="http://www.wattsports.co.uk/wp-content/themes/canvas/template-statistics_details3.php"  title="wattball"  ></a>

</div>

</nav>

ドロップダウンで選択されたアイテムの値を取得し、それをすべての統計ページの "?chosen=" を使用して href の最後に配置する関数。イベントを取得し、選択したイベントの別の統計を開くことができるように

Query(function($) {

 $("select").change(function () 
 {

     var str = "";

     $(this).find("option:selected").each(function () {

          str += $(this).val() + " ";   

          $("a").attr('href', function(i, href) {

                var newUrl =  $(this).attr('href')+'?chosen='+str;

                $(this).attr('href',newUrl);

                 });
           });
    });
});
4

1 に答える 1

0

JQuery で href 属性を変更するとすぐに、それが新しい HREF になります。オプションを 2 回目に選択すると、href にクエリ文字列が追加されます。例えば

 <a class="fancybox"   data-fancybox-type="iframe"  data-fancybox-group="gallery_wattball" href="http://www.wattsports.co.uk/wp-content/themes/canvas/template-statistics_details3.php"  title="wattball"  ></a>

http://www.wattsports.co.uk/wp-content/themes/canvas/template-statistics_details3.phpの href があります。

何かを初めて選択すると、http://www.wattsports.co.uk/wp-content/themes/canvas/template-statistics_details3.php?chosen=somevalueになります。

次に何かを選択すると、

http://www.wattsports.co.uk/wp-content/themes/canvas/template-statistics_details3.php?chosen=somevalue?chosen=SomeOtherValue

新しいクエリ文字列を追加する前に、元の href を保存するか、choose=somevalue クエリ文字列を削除するコードを追加する方法が必要です。

于 2013-03-16T22:58:48.547 に答える