查看: 832|回复: 0

js设置radio的任意选项为选中状态的方法

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2023-12-24 21:50:30 | 显示全部楼层 |阅读模式
点击代码:

  1. <div class="form-group">
  2.                         <label class="col-xs-12 col-sm-3 col-md-2 control-label">卡券形式:</label>
  3.                         <div class="col-sm-9 col-xs-12">
  4.                             <label class="radio-inline">
  5.                                     <input type="radio" name="type" value="1" {if empty($coupon) || $coupon['type'] == '1'} checked="true" {/if} onclick="radio(1)" /> 礼品券
  6.                                 </label>
  7.                             <label class="radio-inline">
  8.                                 <input type="radio" name="type" value="2" {if $coupon['type'] == '2'} checked="true" {/if} onclick="radio(2)" /> 现金券
  9.                             </label>
  10.                             <label class="radio-inline">
  11.                                 <input type="radio" name="type" value="3" {if $coupon['type'] == '3'} checked="true" {/if} onclick="radio(3)" /> 折扣券
  12.                             </label>
  13.                             <label class="radio-inline">
  14.                                 <input type="radio" name="type" value="4" {if $coupon['type'] == '4'} checked="true" {/if} onclick="radio(4)" /> 体验券
  15.                             </label>
  16.                             <label class="radio-inline">
  17.                                 <input type="radio" name="type" value="5" {if $coupon['type'] == '5'} checked="true" {/if} onclick="radio(5)" /> 换购券
  18.                             </label>
  19.                             <label class="radio-inline">
  20.                                 <input type="radio" name="type" value="6" {if $coupon['type'] == '6'} checked="true" {/if} onclick="radio(6)" /> 计次券
  21.                             </label>
  22.                             <label class="radio-inline">
  23.                                 <input type="radio" name="type" value="7" {if $coupon['type'] == '7'} checked="true" {/if} onclick="radio(7)" /> 防伪券
  24.                             </label>
  25.                             <label class="radio-inline">
  26.                                 <input type="radio" name="type" value="8" {if $coupon['type'] == '8'} checked="true" {/if} onclick="radio(8)" /> 溯源券
  27.                             </label>
  28.                                 <span class="help-block">卡券类型设置后不可更改,<text style="color: #ff0000;">计次券只能设置为电子券,防伪券和溯源券只能设置为纸质券</text>(<a href="http://bbs.winchung.com/thread-132-1-1.html" target="_blank">查看说明</a>)</span>
  29.                         </div>
  30.                 </div>
复制代码
选中代码:
  1. <div class="form-group">
  2.                         <label class="col-xs-12 col-sm-3 col-md-2 control-label">卡券形式:</label>
  3.                         <div class="col-sm-9 col-xs-12">
  4.                             <label class="radio-inline">
  5.                                     <input type="radio" name="coupon_type" value="1" {if empty($coupon) || $coupon['coupon_type'] == 1} checked="true" {/if} onclick="$('#total').show();" /> 电子券
  6.                                 </label>
  7.                             <label class="radio-inline">
  8.                                 <input type="radio" name="coupon_type" value="2" {if $coupon['coupon_type'] == 2} checked="true" {/if} onclick="$('#total').hide();" /> 纸质券
  9.                             </label>
  10.                                 <span class="help-block">卡券形式设置后不可更改,<text style="color: #ff0000;">计次券只能设置为电子券,防伪券和溯源券只能设置为纸质券</text></span>
  11.                         </div>
  12.                 </div>
复制代码
js代码:
  1. function radio(id) {
  2.         console.log(id)
  3.         if (id == 7 || id == 8) {
  4.             $("input[name=coupon_type]").eq(1).prop('checked', true);
  5.         } else {
  6.             $("input[name=coupon_type]").eq(0).prop('checked', true);
  7.         }
  8.     }
复制代码


道不同,不相为谋!理想要有,万一实现了呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:2513533699@qq.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鲁ICP备19000917号|鲁公网安备37078302000320号

在本版发帖
关注公众号
QQ客服返回顶部