国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 18:43:15
字體:
供稿:網(wǎng)友

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

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

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

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

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

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

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

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

這里的坑:
$('#myModal').modal('show'); 
如果只用這一行代碼,模態(tài)框就會(huì)瞬間消失。
后面添加代碼:
$('#myModal').on('hide.bs.modal', function () { 
第二步,點(diǎn)擊模態(tài)框的確認(rèn)如何做呢?我這個(gè)方法很笨。下面是模態(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í)這個(gè)是狀況二引發(fā)的關(guān)于【bootstrap modal 模態(tài)框彈出瞬間消失的問題】的另一種解決方式

提供一個(gè)小例子說明。

<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的時(shí)候,照著官網(wǎng)的例子Copy了代碼,在自己的頁面運(yùn)行的時(shí)候窗口彈出,但一瞬間就消失。在網(wǎng)上查了很久也沒個(gè)答案,我是新手,在此請(qǐ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">×</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í)的,請(qǐng)注意,你在官網(wǎng)下載的bootstrap源碼有兩個(gè)版本,如圖:

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

網(wǎng)友3:今天我也遇到了,雖然是三個(gè)月的東西了。但是我還是想把正確答案貼出來,原因是: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個(gè)精彩的專題:

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

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

Bootstrap插件使用教程

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桦南县| 南江县| 五莲县| 安岳县| 剑阁县| 横峰县| 余姚市| 盐边县| 鱼台县| 平山县| 阿鲁科尔沁旗| 枣强县| 贵溪市| 新密市| 太仓市| 凤阳县| 凌海市| 太谷县| 临猗县| 林芝县| 峨眉山市| 漯河市| 莫力| 临澧县| 崇仁县| 银川市| 崇仁县| 南丹县| 盘锦市| 淮南市| 元谋县| 忻州市| 东城区| 台前县| 巩义市| 彩票| 神农架林区| 庐江县| 宽城| 北安市| 高州市|