验证功能不起作用

Validation function not working

本文关键字:不起作用 功能 验证      更新时间:2023-09-26

我正试图在一个按钮上写一个验证语句,说明如果两个特定的文本字段为空,并且他们点击了按钮,那么返回消息"This field is valid"

这是我目前拥有的代码:

    function validateButton(){
    if (tfState.getValue()!=''){
        if (tfCity.getValue()!='') return true;
        else return 'This value is not valid.';
    }
    else return true;
}

我不确定getValue();是什么,但假设tfStatetfCity是对DOM节点的引用:

function validateButton(){
    if (tfState.value !='' && tfCity.value != ''){
        return true;
    }
    return 'This value is not valid.';
}

这就是您想要的

    function validateButton(){
    if ((tfState.val().length != 0) && (tfCity.val().length != 0))
       return true;
    }
      else return 'This value is not valid.';
}