首页 > 解决方案 > 单选按钮的警报消息

问题描述

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

<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>

标签: javascriptjquery

解决方案


这里:

$('#mypayment').click(function(){
   if($('#pricemethod').is(':checked')){
      alert('Please Select Payment options');
   }else{
      $('#spendform').submit();
   }
});

.is(':checked') by MH2K9


推荐阅读