如果条件为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">×</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>
如何实现???
答案 0 :(得分:2)
尝试下面的代码,它的工作正常。我在jsfiddle中创建了链接 http://jsfiddle.net/h3WDq/1543/
<script>
$(function()
{
$("#mybutton").click(function(){
var mycodition=true;
if(mycodition)
$("#myModal").modal('show');
return false;
});
});
答案 1 :(得分:0)
您可以尝试从脚本中打开弹出窗口。
<script type="text/javascript">
function OpenPopup() {
if(condition){
$("#YourModalId").modal('show');
}
}
</script>