如果条件为true,则显示Bootstrap Modal



如果条件为true或false,我想在ASp.net MVC中显示引导模式的按钮点击。比如说,如果我检查了登录凭据,如果失败了,那么如何在引导模式或引导警报中显示错误。

    <html>
<head>
    <link href="~/bootstrap.min.css" rel="stylesheet" />
    <script src="~/bootstrap.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
     <script>
         $(function()
         {
             $("#mybutton").click(function(){
                 var test1 = $('#test').val();
                 if(test1 == "Value")
                     $("#myModal").modal('show');
             });
         });
     </script>
</head>
<body>
        <input type="text" class="form-control" id="test" placeholder="Enter A Value" />
        <button type="submit" value="Click" name="click" id="mybutton">Click Me!</button>            

    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Modal title</h4>
                </div>
                <div class="modal-body">
                    ...
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

如何实现???

尝试下面的代码,它可以正常工作。我在jsfiddle中创建了链接
http://jsfiddle.net/h3WDq/1543/

  <script>
$(function()
{
  $("#mybutton").click(function(){
  var mycodition=true;
  if(mycodition)
   $("#myModal").modal('show');
     return false;
 });
});

您可以尝试从脚本打开弹出窗口。

<script type="text/javascript">
    function OpenPopup() {
        if(condition){
        $("#YourModalId").modal('show');
       }
    }
</script>

相关内容

  • 没有找到相关文章

最新更新