2012-01-30 60 views
0

我试着做下面的事情,通过使用下面的查询更改显示价格和订单的直接链接。JQUERY切换价格和订单链接

function changepricing() { 
    jQuery("#monthly").slideToggle(); 
    jQuery("#monthly1").slideToggle(); 
    jQuery("#montly2").slideToggle(); 
    jQuery("#monthly3").slideToggle(); 
    jQuery("#monthly4").slideToggle(); 
    jQuery("#halfyear").slideToggle(); 
    jQuery("#halfyear1").slideToggle(); 
    jQuery("#halfyear2").slideToggle(); 
    jQuery("#halfyear3").slideToggle(); 
    jQuery("#halfyear4").slideToggle(); 
    jQuery("#annual").slideToggle(); 
    jQuery("#annual1").slideToggle(); 
    jQuery("#annual2").slideToggle(); 
    jQuery("#annual3").slideToggle(); 
    jQuery("#annual4").slideToggle(); 
    jQuery("#biannual").slideToggle(); 
    jQuery("#biannual1").slideToggle(); 
    jQuery("#biannual2").slideToggle(); 
    jQuery("#biannual3").slideToggle(); 
    jQuery("#biannual4").slideToggle(); 
    jQuery("#prcmonthly1").slideToggle(); 
    jQuery("#prcmonthly2").slideToggle(); 
    jQuery("#prcmonthly3").slideToggle(); 
    jQuery("#prcmonthly4").slideToggle(); 
    jQuery("#prchalfyear1").slideToggle(); 
    jQuery("#prchalfyear2").slideToggle(); 
    jQuery("#prchalfyear3").slideToggle(); 
    jQuery("#prchalfyear4").slideToggle(); 
    jQuery("#prcannual1").slideToggle(); 
    jQuery("#prcannual2").slideToggle(); 
    jQuery("#prcannual3").slideToggle(); 
    jQuery("#prcannual4").slideToggle(); 
    jQuery("#prcbiannual1").slideToggle(); 
    jQuery("#prcbiannual2").slideToggle(); 
    jQuery("#prcbiannual3").slideToggle(); 
    jQuery("#prcbiannual4").slideToggle(); 
} 

代码是否

为了显示和改变价格:

<li id="monthly" class="pricing_header2" style="display:block;"><a href="#" onclick="changepricing();return false;"><span>1 Month </span></a></li> 
    <li id="halfyear" class="pricing_header2" style="display:none;"><a href="#" onclick="changepricing();return false;"><span>6 Months </span></a></li> 
    <li id="annual" class="pricing_header2" style="display:none;"><a href="#" onclick="changepricing();return false;"><span>{$LANG.product_choose_one} </span></a></li> 
    <li id="biannual" class="pricing_header2" style="display:none;"><a href="#" onclick="changepricing();return false;"><span>{$LANG.product_choose_two} </span></a></li> 

对于显示器的价格和订单链接:

 <li id="monthly1" class="pricing_header2" style="display:block;">&euro;1 <span>/1 mo.</span></li> 
     <li id="halfyear1" class="pricing_header2" style="display:none;">&euro;2 <span>/6 mos.</span></li> 
     <li id="annual1" class="pricing_header2" style="display:none;">&euro;3 <span>/One yr.</span></li> 
     <li id="biannual1" class="pricing_header2" style="display:none;">&euro;4 <span>/Two yrs.</span></li> 

     <li id="prcmonthly1" class="pricing_footer" style="display:block;"><span><a href="link1" class="pricing_button">{$LANG.product_buy_now}</a></li> 
     <li id="prchalfyear1" class="pricing_footer" style="display:none;"><span><a href="link2" class="pricing_button">{$LANG.product_buy_now}</a></li> 
     <li id="prcannual1" class="pricing_footer" style="display:none;"><span><a href="link3" class="pricing_button">{$LANG.product_buy_now}</a></li> 
     <li id="prcbiannual1" class="pricing_footer" style="display:none;"><span><a href="link4" class="pricing_button">{$LANG.product_buy_now}</a></li> 

上面的代码中正常工作,如果我只用为2产品,但通过使用3或4产品不工作。有任何帮助吗?我真的很感激。

感谢, 曼努埃尔

+0

你将不得不缩进JavaScript代码,我们试着去了解它 – 2012-01-30 13:59:00

+0

你的改变价格方法有点让我头疼,但你可以通过选择class来改变它的方式。像$(“。pricing_header2”)。slideToggle(); – 2012-01-30 13:59:51

+0

嗨,pricing_header来自CSS表格,而不是来自jquery。 jquery的代码是:例如id =“monthly1”。两个产品的代码工作相同,但不适用于4.任何想法?谢谢 – Manuel 2012-01-30 20:38:49

回答

1

哇!

可能我建议把上拨动能项目另一个类(如<li class='pricing_header2 toggleable'>),并使用这个JS代码,而不是:

$('.toggleable').slideToggle(); 
+0

嗨,因为我电话上面的id是更改类“pricing_header2”是CSS的表格样式。我假装是:在这里:http://www.kanumhost.com/ssl-certificates是两个产品。在这里工作http://www.kanumhost.com/reseller.php提供四种产品。非常感谢。 – Manuel 2012-01-30 20:41:43

1

如果您有一组这些div的每个产品不是我真的徘徊它如何为2刺激工作? MikaelHärsjö说过的任何方式,在处理项目列表时使用类而不是id。你不能有更多的一个div id =“foo”,但你可以有无限的div class =“foo”。

所以,我设法凑了这一功能:

function changepricing(_from, _to) { 
    for(i=0; i<=4; i++) { 
    if(i == 0) { 
     nr = ''; 
    } 
    else { 
     nr = i; 
    } 
    jQuery("#"+_from+nr).slideToggle(); 
    jQuery("#"+_to+nr).slideToggle(); 
    } 
} 

为了让它工作,你就必须拨打电话,像这样:

<li id="monthly" class="pricing_header2" style="display: block;"> 
    <a onclick="changepricing('monthly', 'halfyear');return false;" href="#"> 
    <span>1 Month </span> 
    </a> 
</li> 
+0

嗨,你能给我一个例子工作的代码,我需要为这项工作添加?非常感谢所有 – Manuel 2012-01-31 13:45:09

+0

嗨,我已经改变了所有使用类,但仍然没有工作,请看看这里:http://www.kanumhost.com/reseller.php不改变显示价格,但隐藏一个月,并显示半年,一年和两年。什么可能是错误的?非常感谢 – Manuel 2012-01-31 19:28:26

+0

这种设计可能会出现许多问题,但我设法从答案中挖掘出功能。看看上面修改的答案。 – 2012-01-31 22:05:17