gpt4 book ai didi

javascript - 如何在复选框激活时禁用/启用 PayPal 按钮?

转载 作者:行者123 更新时间:2023-11-29 10:51:18 24 4
gpt4 key购买 nike

我的网站上有一个页面设置为定期付款,但我想禁用 PayPal 结帐按钮,直到有人选中同意我的服务条款的复选框。你能帮我弄清楚如何正确地做到这一点吗?

谢谢!!!!-布拉德

最佳答案

<p id="error" class="hidden">Please check the checkbox</p>
<label><input id="check" type="checkbox"> Check here to continue</label>

<script>
paypal.Buttons({

// onInit is called when the button first renders
onInit: function(data, actions) {

// Disable the buttons
actions.disable();

// Listen for changes to the checkbox
document.querySelector('#check')
.addEventListener('change', function(event) {

// Enable or disable the button when it is checked or unchecked
if (event.target.checked) {
actions.enable();
} else {
actions.disable();
}
});
},

// onClick is called when the button is clicked
onClick: function() {

// Show a validation error if the checkbox is not checked
if (!document.querySelector('#check').checked) {
document.querySelector('#error').classList.remove('hidden');
}
}

}).render('#paypal-button-container');
</script>

关于javascript - 如何在复选框激活时禁用/启用 PayPal 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9707024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com