javascript - 用于更改价格和订单链接的 JQUERY 切换

标签 javascript jquery toggle slidetoggle

我尝试执行以下操作,通过使用以下查询更改显示价格和订单的直接链接。

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 个产品就不起作用。有人可以帮忙吗?我真的很感激。

谢谢, 曼努埃尔

最佳答案

哇!

我可以建议在可切换项上放置另一个类(例如 <li class='pricing_header2 toggleable'> )并使用以下 JS 代码:

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

关于javascript - 用于更改价格和订单链接的 JQUERY 切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9064949/

相关文章:

javascript - 当另一个 ul 被点击事件切换时关闭所有打开的 ul

javascript - 三.js加载json字符串

javascript - 显示选定的菜单项必须显示在父项中

javascript - 使用javascript正则表达式替换时忽略html实体

javascript - 未捕获的语法错误 : Unexpected token < while calling cakephp select form directly in javascript

php - 使用 PHP 从 MySQL 获取新添加的行

javascript - 单击切换多个目标

javascript - 如何在chart.js中显示每个切片的饼图数据值

Javascript innerHTML 忽略文本格式

jquery 1.10 并使切换事件自动运行