如何隐藏if语句?或者其他可以使用的技术

how to hide an if statment? or whatever technique can be done?

本文关键字:其他 或者 可以使 技术 语句 何隐藏 隐藏 if      更新时间:2023-09-26

我有一个外部javascript文件,它有多个if语句,问题是,即使表单被隐藏,其中一个if语句仍然被调用。我的申请是这样的,-当用户登录时,隐藏这个特定的输入表单-如果未登录,显示输入表单

这就是问题所在,使用javascript的输入表单的if语句,仍然被调用即使输入表单是隐藏的,我该怎么做来解决这个问题呢?

下面是输入表单 的if语句
     if(cvusername == "" || cvusername.length < 5 || cvusername.length > 30){
    alert("-username is required'n-should not be less than 5 characters'n and not greater than 30 characters");
    return false;
 }

假设您的输入表单的id是input_form,执行如下操作:

if(document.getElementById("input_form").style.display !== "none"
    && (
        cvusername == ""  
        || cvusername.length < 5
        || cvusername.length > 30) 
    ){
    alert("-username is required'n-should not be less than 5 characters'n and not greater than 30 characters");
    return false;
 }

要么从页面中删除该脚本,要么将cvusername设置为每个页面中5到30个字符之间的任意字符串

cvusername = "loggedin";