j查询单选按钮已选中,仍显示错误



我有一个单选按钮,在表单提交时,我正在检查它是否被选中,如果没有显示错误消息。 单击单选按钮时,删除错误消息。但即使选择了单选按钮,它仍然返回 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;
}

更改:

if (radio_not_selected) {

自:

if (radio_not_selected()) {

您没有使用您的函数。更改此设置:

if (radio_not_selected) {

自:

if (radio_not_selected()) {

相关内容

最新更新