账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    JavaScript 判断条件写法(基础问题)
    32
    0

    想要达到的目的:判断内容全为 空格时,禁止按钮使用。

    全部输入空格提示另一种方法:
    Ts:
    pattern: any = { space: '(^1+$)' };

    template:
    <textarea [(ngModel)]="EvaluateInfo.content" (input)="getValue()" [pattern]="pattern.space #aName="ngModel" required ...>

    <div *ngIf="aName.invalid && (aName.dirty || aName.touched)">
    <div *ngIf=aName.errors.required">...</div>
    <div *ngIf="aName.errors.pattern">...</div>
    </div>

    判断条件如下:
    (问题出在后半部分,即判断内容是否全部为空格,
    (this.EvaluateInfo.content.replace('\s+', '').length > 0)

    private EvaluatEInfo = {content: ''}
    [disabled] = "publishctrl"    // 控制按钮是否可用
    
    if (this.EvaluateInfo.content.length > 0){
      this.publishctrl = false;
    }
    else if((this.EvaluateInfo.content.length <= 0 || (this.EvaluateInfo.content.replace('\s+', '').length > 0))
    { this.publishctrl = true;}

    1. \s
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 乱世狂刀 普通会员 1楼

      在JavaScript中,你可以使用条件语句(如if,else,switch)来判断条件。下面是一个基础的if语句的示例:

      javascript let num = 10; if (num > 5) { console.log(num + " is greater than 5"); } else { console.log(num + " is less than or equal to 5"); }

      在这个例子中,我们有一个变量num,它的值为10。然后我们使用一个if语句来检查num是否大于5。如果是,我们就打印出num + " is greater than 5",否则我们就打印出num + " is less than or equal to 5"

      在JavaScript中,你也可以使用switch语句来根据不同的条件执行不同的代码块:

      javascript let num = 10; switch (num) { case 10: console.log("num is equal to 10"); break; case 20: console.log("num is greater than 20"); break; case 30: console.log("num is less than or equal to 30"); break; default: console.log("num is not equal to 10, 20, or 30"); }

      在这个例子中,我们有一个变量num,它的值为10。然后我们使用一个switch语句来根据num的值执行不同的代码块。如果num等于10,我们就打印出num is equal to 10,然后退出switch语句。如果num大于20,我们就打印出num is greater than 20,然后退出switch语句。如果num小于或等于30,我们就打印出num is less than or equal to 30,然后退出switch语句。如果num的值不在10,20或30之间,我们就打印出num is not equal to 10, 20, or 30

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部