dongzhimin2231 2014-12-28 22:53
浏览 29
已采纳

使用javascript或jQuery更新两个复选框选择的价格

I need a way to show correct price for a product with selection options. Radio Box 1 has 4 products with different price ProductA=$10, ProductB=$20, ProductC=$30, ProductD=$40

Radio Box 2 has two options Male and Female

For female all products are always $10 regardless of Radio Box 1 selection. Price varies for men depending on product choice. I need to show price change dynamically with js.

http://jsfiddle.net/pe2gpp01/

<div><label class="product">Product</label>
<span>
<input name="category" type="radio" value="10">
<label>Product A</label>
<input name="category" type="radio" value="20">
<label>Product B</label>
<input name="category" type="radio" value="30">
<label>Product C</label>
<input name="category" type="radio" value="40">
<label>Product D</label>
</span></div>

<div>
<label class="gender">Gender</label>
<span>
<input name="gender" type="radio" value="">
<label>Male</label>
<input name="gender" type="radio" value="">
<label>Female</label>
</span></div>

<span>Price:</span>
  • 写回答

1条回答 默认 最新

  • dongxia8656 2014-12-28 23:12
    关注

    DEMO

    checks

    html

    <div>
    <label class="product">Product</label>
    <span>
    <input name="category" type="radio" value="10" >
    <label>Product A</label>
    <input name="category" type="radio" value="20" checked>
    <label>Product B</label>
    <input name="category" type="radio" value="30">
    <label>Product C</label>
    <input name="category" type="radio" value="40" >
    <label>Product D</label>
        </span></div>
    
    <div>
    <label class="gender">Gender</label>
    <span>
    <input name="gender" type="radio" value="male" checked>
    <label>Male</label>
    <input name="gender" type="radio" value="female">
    <label>Female</label>
        </span></div>
    
        <span>Show Price: <span id="price"></span></span>
    

    js

    $(function() {
        $('[type="radio"]').on('change', function() {
            var price = $('[value="female"]')[0].checked
              ? 10 
              : $('[name="category"]:checked').val();
    
           $('#price').text(price);
    
        }).change();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题