繁体   English   中英

检查是否已将课程添加到 <li> 选择单选按钮时

[英]check is class has been added to <li> when radio button selected

我在Give插件中有两个单选按钮的以下代码:

<li class="give-gateway-option-selected">
  <input type="radio" name="payment-mode" class="give-gateway" 
     id="give-gateway-offline-987-1" value="offline">
  <label for="give-gateway-offline-987-1" 
    class="give-gateway-option" id="give-gateway-option-offline">
    Credit Card
  </label>
</li>
<li>
   <input type="radio" name="payment-mode" class="give-gateway" id="give- 
      gateway-paypal-987-1" value="paypal">
   <label for="give-gateway-paypal-987-1" class="give-gateway-option" 
      id="give-gateway-option-paypal"> PayPal
   </label>
</li>

如果选中了单选按钮,则会添加一个类。 假设我选中了“信用卡”选项。 添加了以下类:

<li class="give-gateway-option-selected">
<input type="radio" name="payment-mode" class="give-gateway" 
id="give-gateway-offline-987-1" value="offline">
<label for="give-gateway-offline-987-1" 
class="give-gateway-option" id="give-gateway-option-offline"> Credit Card</label>
</li>

我需要编写一些javascript / jQuery来检查是否选中了“信用卡”单选框,然后重定向到特定的URL。 但是我不能用

if ($('#give-gateway-offline-987-1').is(':checked'))) { //redirect code }

因为没有将'checked'值添加到<input>而是将一个类添加到了<li>标签中。 如何检查是否已添加该类,然后运行重定向?

:checked选择器确实适用于单选按钮,请参见此处: https : //api.jquery.com/checked-selector/

如果您确实需要使用类方法,请检查父jquery方法是否保持如下所示的结构:

if($('#give-gateway-offline-987-1').parent().hasClass('give-gateway-option-selected')) {
    //redirect
    window.location.href = 'http://www.google.com';
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM