【问题标题】:check radio button as default默认选中单选按钮
【发布时间】:2016-10-11 13:21:41
【问题描述】:

我有几个复选框: a-贝佐根 b- afhalen。

如果选中了 Afhalen,则必须选中复选框 betaal op rekening。

但现在只有第一次检查 afhalen 时才会检查单选按钮 betaal op rekening。但是,如果你去 bezorgen 然后回到 afhalen,则不再检查单选按钮 betaal op rekening。但必须检查。

我有这个:

    @if (GetBoolean("bdCanOrderOnAccount"))
{
string ischecked = GetString("User.bdDefaultPickupOrDelivery.Value").Equals("afhalen") ? "checked" : null;
<div class="control-group">
  <input type="radio" value="PAY1" id="EcomCartPaymethodID_PAY1a" name="EcomCartPaymethodID"  class="pull-left"  @if (GetString("Ecom:Order.PaymentMethodID").Equals("PAY1")){ 
  <text> checked="checked" </text>
  }>
  <label for="EcomCartPaymethodID_PAY1a" class="pull-left radio-label">@Translate("choosepaymentmethodebankaccount", "Betaal op rekening")</label>
</div>
}
<!--
  <div class="control-group">
    <input type="radio" value="PAY2" id="EcomCartPaymethodID_PAY2a" name="EcomCartPaymethodID" class="pull-left" @if (GetString("Ecom:Order.PaymentMethodID").Equals("PAY2")) { <text> checked="checked" </text>          }>
    <label for="EcomCartPaymethodID_PAY2a" class="pull-left radio-label">@Translate("choosepaymentmethodeideal", "Betaal online via iDeal")</label>
  </div>
                                    -->
<div class="control-group">
  <input type="radio" value="PAY3" id="EcomCartPaymethodID_PAY3a" name="EcomCartPaymethodID" class="pull-left" @if (GetString("Ecom:Order.PaymentMethodID").Equals("PAY3")) { 
  <text> checked="checked" </text>
  }>
  <label for="EcomCartPaymethodID_PAY3a" id='labelPay' class="pull-left radio-label">@Translate("choosepaymentmethodepickup", "betaal bij afhalen")</label>
</div>
</div>
@if (GetBoolean("bdCanOrderOnAccount")){
<script>
  $(function () {                                
  $('#EcomCartPaymethodID_PAY3a').parent().hide();  
  $("#EcomCartPaymethodID_PAY1a").prop('checked', true); 
  //alert('test')                          



    });





</script>                             
}
<script>
  $(function () {       
  if ($("#levering-optie-afhalen").prop("checked")) {
                    alert('true');
  $("#EcomCartPaymethodID_PAY1a").prop('checked', true); 

       alert('false');

  }
  });
</script>

这样:

   <script>
  $(function () {       
  if ($("#levering-optie-afhalen").prop("checked")) {
                    alert('true');
  $("#EcomCartPaymethodID_PAY1a").prop('checked', true); 

       alert('false');

  }
  });
</script>

我检查单选按钮 afhalen 是否被选中。

谢谢

尼尔斯

如果选中此项:

 <input type="radio" name="levering-opties" id="levering-optie-afhalen" value="afhalen" checked="@ischecked">

那么这也必须检查:

<div class="control-group">
  <input type="radio" value="PAY1" id="EcomCartPaymethodID_PAY1a" name="EcomCartPaymethodID"  class="pull-left"  @if (GetString("Ecom:Order.PaymentMethodID").Equals("PAY1")){ 
  <text> checked="checked" </text>
  }>
  <label for="EcomCartPaymethodID_PAY1a" class="pull-left radio-label">@Translate("choosepaymentmethodebankaccount", "Betaal op rekening")</label>
</div>

【问题讨论】:

  • 我迷失了所有这些不可读的名称、代码和错误的缩进但是只能按组检查一个单选按钮(名称属性),所以我不确定你在期待什么?!。 ..
  • 请按照之前的要求正确格式化您的代码
  • ok,已经做到了

标签: javascript jquery razor


【解决方案1】:

好吧,

这就是解决方案:

@if (GetBoolean("bdCanOrderOnAccount")){
<script>
  $(function () {                                
  $('#EcomCartPaymethodID_PAY3a').parent().hide();  
  $("#EcomCartPaymethodID_PAY1a").prop('checked', true); 

  $('input[type=radio]').change(function()
  {
  if ($('#levering-optie-afhalen').is(':checked')) 
  { 
  $("#EcomCartPaymethodID_PAY1a").prop('checked', true); 
  }
  });
  });                                
</script>                                                                   
}

【讨论】:

    猜你喜欢
    • 2018-12-26
    • 2017-10-02
    • 2014-03-08
    • 2018-04-21
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    相关资源
    最近更新 更多