0

我决定通过 url 从下拉列表中将选定的数据发送到我页面上的几个链接,这些链接打开不同的幻想框。但它只工作一次。

它打开了发送正确数据的fancybox,但是当我关闭fancybox(这意味着它不会刷新我的页面只是fancybox之一)并且我更改下拉列表的值并重新打开我的fancybox时,发送的值没有改变我坚持第一个发送值。

你能帮助我并向我解释为什么它不起作用,我是 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。第二次选择一个选项时,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,或者在添加新查询字符串之前添加代码以删除 selected=somevalue 查询字符串。

于 2013-03-16T22:58:48.547 回答