簡體   English   中英

單選按鈕的警報消息

[英]alert message for radio button

我嘗試生成警報消息。未選中單選按鈕時。 這是我的代碼。

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

這里:

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

.is(':checked')由MH2K9

使用.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-ph btn-bw" id="mypayment">Make Investmen</button> </form> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM