gpt4 book ai didi

javascript - 单选按钮的警报消息

转载 作者:行者123 更新时间:2023-11-30 06:14:17 25 4
gpt4 key购买 nike

我正在尝试生成警告消息。当单选按钮未选中时。这是我的代码。

<form method=post name="spendform" id="spendform">
<input name="price" type="radio" class="invest-coin-check" id="pricemethod" >
<button type=submit class="btn btn-lg btn-p-h btn-bw" id="mypayment">Make Investmen

t这是java脚本代码

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#mypayment').click(function () {
if ($('#pricemethod').val() == '') {
alert('Please Select Payment options');
return false;
}
});
});
</script>

最佳答案

使用 .is(':checked') 而不是 .val().is(':checked')如果被选中则返回true,否则返回false

$(document).ready(function() {
$('#mypayment').click(function(){
if(!$('#pricemethod').is(':checked')){
alert('Please Select Payment options');
return false;
}
});
});
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<form method=post name="spendform" id="spendform">
<input name="price" type="radio" class="invest-coin-check" id="pricemethod" >
<button type=submit class="btn btn-lg btn-p-h btn-bw" id="mypayment">Make Investmen</button>
</form>

关于javascript - 单选按钮的警报消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57186798/

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