亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

bootstrap模態(tài)框消失問題的解決方法

 更新時間:2016年12月02日 09:15:13   投稿:lijiao  
這篇文章主要為大家詳細(xì)整理了bootstrap模態(tài)框消失不消失各種問題的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

小編主要從網(wǎng)上整理了網(wǎng)友提出來的關(guān)于bootstrap模態(tài)框消失的不同問題,希望對大家有幫助。

狀況一:bootstrap模態(tài)框瞬間消失解決

bootstrap模態(tài)框挺好,但這方面的例子很少,都是官方的代碼,網(wǎng)上沒有一點(diǎn)新的東西。比如,save changes,即點(diǎn)擊確認(rèn)后如何處理?沒有例子。只有取消close的功能。我的需求是這樣,點(diǎn)擊一個鏈接,傳一個id,打開模態(tài)框,進(jìn)行輸入、單選、列表選擇等,點(diǎn)模態(tài)框確認(rèn),然后連同剛才的id、模態(tài)框中的各種值,一起提交到后臺處理。

第一步:用鏈接傳id并打開模態(tài)框。

<a href="" data-toggle="modal" onclick="prom('{{$.Category.Id}}')">添加同級</a> 

{{$.Category.Id}}是傳的id值

通過js代碼實(shí)現(xiàn)打開模態(tài)框

<script type="text/javascript"> 
 
//添加同級 
 function prom(id) { 
 $('#myModal').modal('show'); 
 $('#myModal').on('hide.bs.modal', function () { 
 var radio =$("input[type='radio']:checked").val(); 
 alert("您選擇的是:" + radio + "。抱歉!添加功能暫時不提供。"); 
 }); 
 // if (cname) 
 // { 
 // $.ajax({ 
 // type:"post", 
 // url:"/category/post", 
 // data: {pid:id,title:cname},//父級id 
 // success:function(data,status){ 
 // alert("添加“"+data+"”成功!(status:"+status+".)"); 
 // } 
 // }); 
 // } 
 } 

這里的坑:
$('#myModal').modal('show'); 
如果只用這一行代碼,模態(tài)框就會瞬間消失。
后面添加代碼:
$('#myModal').on('hide.bs.modal', function () { 
第二步,點(diǎn)擊模態(tài)框的確認(rèn)如何做呢?我這個方法很笨。下面是模態(tài)框的按鈕,我用取消代替確定。

<div class="modal-footer"> 
 <button type="button" class="btn btn-default" data-dismiss="modal">確定</button> 
 <!-- <button type="button" class="btn btn-primary">Save changes</button> --> 
</div> 

在點(diǎn)擊確定(其實(shí)是關(guān)閉)后,觸發(fā)了
$('#myModal').on('hide.bs.modal', function () { 
開始執(zhí)行里面的代碼了。

狀況二:bootstrap中的模態(tài)框插件,點(diǎn)擊遮蓋層,模態(tài)框不消失,怎么讓消失

代碼:

復(fù)制代碼 代碼如下:
<button type="button" class="btn btn-primary " data-toggle="modal" data-target="#myModal"> Launch demo modal </button> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal...

熱心網(wǎng)友給出的答案:

小編有點(diǎn)暈,不知大家明白了嗎?

 狀況三:其實(shí)這個是狀況二引發(fā)的關(guān)于【bootstrap modal 模態(tài)框彈出瞬間消失的問題】的另一種解決方式

提供一個小例子說明。

<button class="btn btn-primary btn-lg" type="button" data-toggle="modal"data-target="#myModal">
 Launch demo modal
 </button>

注意紅字部分type="button",在需要觸發(fā)的按鈕處,加入這一段就好了。

狀況四:這是網(wǎng)友使用bootstrap總結(jié)出來的經(jīng)驗(yàn)不讓modal框消失的方法

If using javascript then:

$('#myModal').modal({
 backdrop: 'static',
 keyboard: false
})
and if HTML:

<a data-controls-modal="your_div_id" data-backdrop="static" data-keyboard="false" href="#">

狀況五:bootstrap modal 模態(tài)框彈出瞬間消失問題的解決方法

問題:

學(xué)習(xí)使用bootstrap modal的時候,照著官網(wǎng)的例子Copy了代碼,在自己的頁面運(yùn)行的時候窗口彈出,但一瞬間就消失。在網(wǎng)上查了很久也沒個答案,我是新手,在此請教在線各位。

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
 + request.getServerName() + ":" + request.getServerPort()
 + path + "/";
%>
 
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Index</title>
 
<link href="Bootstrap/css/bootstrap.css" rel="stylesheet">
 
<style type="text/css">
body {
 padding-top: 50px;
}
.starter-template {
 padding: 40px 15px;
 text-align: center;
}
</style>
 
</head>
<body>
 
 
 <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
 <div class="container">
 <div class="navbar-header">
 <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
 <span class="sr-only">Toggle navigation</span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 </button>
 <a class="navbar-brand" href="#">Project name</a>
 </div>
 <div class="collapse navbar-collapse">
 <ul class="nav navbar-nav">
 <li class="active"><a href="#home">Home</a></li>
 <li><a href="#about">About</a></li>
 <li><a href="#info">Information</a></li>
 <li><a href="#contact">Contact</a></li>
 </ul>
 </div>
 </div>
 </div>
 
 <div class="container">
 
 <!-- Button trigger modal -->
 <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
 Launch demo modal
 </button>
 
 <!-- Modal -->
 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <div class="modal-dialog">
 <div class="modal-content">
 <div class="modal-header">
 <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</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>
 
 </div>
 
 
 
 <script src="jquery/jquery-1.11.1.js"></script>
 <script src="Bootstrap/js/bootstrap.js"></script>
 <script src="Bootstrap/js/transition.js"></script>
 <script src="Bootstrap/js/modal.js"></script>
</body>
</html>

就這樣一瞬間就消失了

網(wǎng)友1:去掉引用modal.js試試?

網(wǎng)友2:各位,樓主的問題解決了。
我猜各位應(yīng)該都是照著bootstrap官網(wǎng)demo在練習(xí)的,請注意,你在官網(wǎng)下載的bootstrap源碼有兩個版本,如圖:

官網(wǎng)Demo使用的是第一個,所以如果你按照官網(wǎng)的Demo練習(xí),那就應(yīng)該只使用第一個,當(dāng)然也可以使用第二個,但是不能混用。

網(wǎng)友3:今天我也遇到了,雖然是三個月的東西了。但是我還是想把正確答案貼出來,原因是:bootstrap.min.js(bootstrap.js) 和modal.js重復(fù)引用,把 modal.js刪除掉就好了。

網(wǎng)友4:我也遇到類似問題,但是解決方式是刪了bootstrap.min.js;js沖突問題

如果大家還想深入學(xué)習(xí),可以點(diǎn)擊這里進(jìn)行學(xué)習(xí),再為大家附3個精彩的專題:

Bootstrap學(xué)習(xí)教程

Bootstrap實(shí)戰(zhàn)教程

Bootstrap插件使用教程

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論