【发布时间】:2019-11-27 08:17:30
【问题描述】:
当单选按钮更改时,我需要隐藏一个元素,现在它可以在 ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js 版本中正常工作,但还有很多其他的东西,比如滑块,当我在我的 opencart 网站中包含此 jquery 时,结帐、运输方式受到干扰。 关于如何使用简单的 javascript 或任何其他方法来做到这一点的任何建议?
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
$('input:radio[name=custom_field[6]]').change(function() {
if (this.value == '2') {
$('input:radio[name=payment_method][value=cod]').show();
$('div.checkout-payment-methods div.radio:nth-child(5)').show();
}
else if (this.value == '1') {
$('input:radio[name=payment_method][value=cod]').hide();
$('div.checkout-payment-methods div.radio:nth-child(5)').hide();
}
});
});
</script>
<div id="input-payment-custom-field6">
<div class="radio">
<label>
<input type="radio" name="custom_field[6]" value="2">
Evidence
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="custom_field[6]" value="1">
Invoice (Can not issue invoice with cash on delivery)
</label>
</div>
</div>
<div class="checkout-content checkout-payment-methods">
<h2 class="secondary-title">Means of payment</h2>
<div class="radio">
<label>
<input type="radio" name="payment_method" value="hellaspay" checked="checked">
Debit / Credit card
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="payment_method" value="bank_transfer">
Bank deposit
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="payment_method" value="pp_standard">
PayPal
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="payment_method" value="cod">
Pay on delivery
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="payment_method" value="pay_at_store">
Payment at Stark
</label>
</div>
</div>
【问题讨论】:
-
你应该使用
$('input:radio[name="custom_field[6]"]').click(function(){ if( $(this).is("checked") ) { // Do something } else { // Do something } }) -
有什么方法可以在不使用jquery的情况下实现当前结果?
-
能否分享你的代码html部分
-
添加了 HTML 部分,当在第一个无线电组中选择发票时,我想在第二个无线电组中隐藏货到付款。注意* HTML 不可编辑
标签: javascript jquery if-statement select radio-button