我這里有一個奇怪的問題,有(未)選中的單選按鈕。我的代碼:function validate(el) { if ($('#type_P').is(':checked') === true && (parseInt($('#voucher_price').val()) <= 0) || isNaN(parseInt($('#voucher_price').val()))) { alert($('#type_P').is(':checked') === true); $('#service_price').addClass('error'); $('#service_price').parent().addClass('error'); } return false;}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><form onsubmit="return validate(this)"> P: <input type="radio" checked name="type" id="type_P" value="P"> S: <input type="radio" name="type" id="type_S" value="S"> <input id="voucher_price"> <input type=submit></form>當選中“type_S”而不是“type_P”時,它會在警報中返回“false”。我的意思是不必顯示任何警報。為什么?當 if 語句中存在相同條件時,如何顯示此警報?
無線電檢查驗證失敗
牧羊人nacy
2023-05-19 16:44:40