dongre6404 2014-09-15 12:06
浏览 27
已采纳

根据发现的错误显示不同的Bootstrap警报消息?

I not exactly sure how to example this but here goes !

I am wanting to add alert messages into a website I am creating. Examples can be found here:

Examples of Alert Messages

Depending on inputs from a form I want to display different messages. So php checks for correct inputs and fields selected.

Examples of Messages:

1) Alert Danger - a password must be between 6 and 16 character long and include letters and numbers

2) Alert Warning - Update your profile.

I want all these messages to be display within the same div tag - message-warning-display.

<div class="message-warning-display" display:"hide">
      <div class="alert alert-warning">
        <a href="#" class="close" data-dismiss="alert">&times;</a>
        <strong>Warning!</strong> There was a problem with your network connection.
      </div>
</div>

I imagine it is something to with php calling a particular JavaScript function which is called and then shows the message / set the display to show instead of hide.

  • 写回答

1条回答 默认 最新

  • dongyejun1983 2014-09-15 12:19
    关注

    One way of doing it would be like:

    Add this to you HTML:

    <div id="alert" class="message-danger-display" style="display:none">
          <div class="alert alert-warning">
             <a href="#" class="close" data-dismiss="alert">&times;</a>
             <p></p>
         </div>
     </div>
    

    YOUR JQUERY PART

    $('YOUR FORM').submit(function(e){
         $('#alert').attr('style','display:none');  
         $('#alert .alert p').html();      
         if('YOUR_DANGER_ALERT_CONDITION'){
               var msg = '<strong>Error!</strong> There was a problem with your network connection.';
               $('#alert .alert p').html(msg);  
               $('#alert').removeClass();
               $('#alert').addClass('message-danger-display');
               $('#alert').removeAttr('style');
               e.preventDefault();
         }else if('YOUR_WARNING_ALERT_CONDITION'){
               var msg = '<strong>Warning!</strong> There was a problem with your network connection.';
               $('#alert .alert p').html(msg);  
               $('#alert').removeClass();
               $('#alert').addClass('message-warning-display');
               $('#alert').removeAttr('style');
               e.preventDefault();
         }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料