选中单选按钮作为默认值

时间:2016-10-11 13:21:41

标签: javascript jquery razor

我有几个复选框: a- bezorgen b- afhalen。

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

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

我有这个:

    @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>

我检查是否检查过radiobutton 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>

1 个答案:

答案 0 :(得分:0)

Oke,

这是解决方案:

@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>                                                                   
}