我有一个表格,在“继续结帐”链接之前的末尾带有“单击此处接受条款和条件”复选框。
使用 jQuery,我想在未选中复选框时删除“继续购物”链接的 href 属性,并且当用户选择复选框时,href 属性将添加回链接。
我正在使用的代码如下,但由于某种原因这不起作用:
jQuery(document).ready(function() {
if ($('input#tandc').is(':checked')) {
jQuery("#continue_shopping").attr("href");
}
else
jQuery("#continue_shopping").removeAttr("href").css({"opacity" : "0.3", "cursor":"default"});
});
我的 html 标记是这样的:
<input type="checkbox" name="tandc" value="tandc" id="tandc" required>
I accept the <a href="/terms-and-conditions">Terms and Conditions</a>
</input>
<a id="continue_shopping" href="/store/shopping-cart/shipping/">Continue Shopping</a>