我有一个单选按钮,在表单提交时,我正在检查它是否被选中,如果没有显示错误消息。单击单选按钮时,删除错误消息。但是,即使选择单选按钮,它仍然返回true并显示错误。请帮帮忙。我尝试过调试,但是由于jquery控件在jquery库中,所以很难调试。
这就是我要做的
$('input:radio').on('click', function (e) {
$('#errgender').text("*");
});
$(':submit').on('click', function (e) {
var valid = false;
if (radio_not_selected) {
valid = true;
$('[name="gender"]').focus();
$('#errgender').text("Please specify gender");
}
if (valid) e.preventDefault();
});
function radio_not_selected() {
var radio = $("input[name='gender']:checked");
if (radio.length <= 0) return true;
else return false;
}发布于 2013-11-01 22:10:46
更改:
if (radio_not_selected) {至:
if (radio_not_selected()) {发布于 2013-11-01 22:11:46
你没有使用你的功能。改变这一点:
if (radio_not_selected) {至:
if (radio_not_selected()) {https://stackoverflow.com/questions/19736161
复制相似问题