javascript - 单选按钮的警报消息
问题描述
我正在尝试生成警报消息。当单选按钮未选择时。这是我的代码。
<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') by MH2K9
推荐阅读
- javascript - 如何在 JavaScript 中将多行字符串值转换为合法的 JSON 字符串变量?
- javascript - 仅打印负数及其和循环和数组
- php - Composer 找不到类...但找到同级文件
- c++ - 反斜杠和引号不计入字符串长度?
- kotlin - Kotlin flatmap 解压数据类列表
- python - 是否有错误的解决方案:condarc invalid yaml 和 ConfigurationLoadError: Unable to load configuration file?
- angular - 动态地将文本墙上的每个单词转换为 Angular 7 中调用角度函数的(点击) - 使用什么?
- spring - 对于 Kotlin 未经检查的异常,Spring 不会回滚事务
- r - 在R图中用具有相同长度但半高的矩形替换正方形
- angular - 将参数传递给 Angular 组件中的 getter 的替代方法