我有一个代码验证所有表单字段是否填充了数据,但我的表单输入是根据this.id_company条件动态显示的.正如您所看到的那样,如果this.is_company等于TRUE那么验证也应检查用户是否已插入this.taxNumber和this.copmany
isComplete: function () {
if (this.is_company) {
return this.firstName && this.lastName && this.email && this.password && this.address && this.postNumber
&& this.city && this.id_country && this.iAggre && this.taxNumber && this.company
}
return this.firstName && this.lastName && this.email && this.password && this.address && this.postNumber
&& this.city && this.id_country && this.iAggre;
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找简化我的Javascript代码的最佳方法.你能不能提供一些例子.谢谢
为了方便,只需使用或:
return (
this.firstName &&
this.lastName &&
this.email &&
this.password &&
this.address &&
this.postNumber &&
this.city &&
this.id_country &&
this.iAggre &&
(!this._isCompany || this.taxNumber && this.company)
);
Run Code Online (Sandbox Code Playgroud)
被视为和不是公司或具有taxNumber和公司财产.
| 归档时间: |
|
| 查看次数: |
84 次 |
| 最近记录: |