代码之家  ›  专栏  ›  技术社区  ›  Hex

如果有条件更改样式类值,是否可以使用Jade?使用flash变量

  •  0
  • Hex  · 技术社区  · 7 年前

    目前,如果登录不成功,我在登录时收到的消息没有问题,但如果有任何消息,我想显示一个div(这次只显示错误消息)

    这是代码

        div(class='formPosSize')
            form(action='/auth/login' method='post' autocomplete='off')
              fieldset
                legend.legend Login
                .input
                  input(name='username', placeholder='Email', required='')
                  span
                    i.fa.fa-envelope-o
                .input
                  input(type='password',name='password', placeholder='Password', required='')
                  span
                    i.fa.fa-lock
                button.submit(type='submit')
                  i.fa.fa-long-arrow-right
    
    
              .feedback(class=message!=="undefined" ? "" : "feederror")
                 if(message)   
                   |  #{message} 
    

    如果有任何消息,我想将当前反馈样式变量“display:none and opacity:0”更改为“display:block and opacity:1”a

    feedback类只是一个矩形,我想在其中显示消息值,如果它确实存在,则显示它

    我也试过了,但没用

                 if(message)  
                  .feedback(class=feederror) 
                     |  #{message} 
    

    我有另一个叫做“feederror”的类,它与feedback相同,但区别在于不透明度和显示。。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Hex    7 年前

    我终于修好了!

    一个下午输了,但胜利了!

    每当您得到“message”变量时,最好检查其长度,而不是检查是否存在、是否为空或是否为真:

    此代码:

    if (message.length > 0)
        div.feederror 
           div #{message}
    

    如果消息变量上有任何内容,则生成:

     <div class="feederror"> 
      <div>Usuario o contraseña incorrectas.</div>
     </div>
    

    若消息并没有任何内容或不存在,则它不会生成任何内容。

    当您需要显示一个已经设计好的div,其类(在我的代码中是feederror)包含来自flash的消息变量时,这会很有帮助。