[英]Conflict between jquery and bootstrap
I have a code where I am including jquery files and bootstrap files in the header.php. 我有一个代码,我在header.php中包含jquery文件和bootstrap文件。 I am running into issues where if I include the jquery file before bootstrap.js file, it messes up the other tabs on my webpage and basically even if i click on the other tabs it does not navigate me.
我遇到的问题是,如果我在bootstrap.js文件之前包含jquery文件,它会弄乱我的网页上的其他选项卡,基本上即使我点击其他选项卡它也不会导航我。
I think there is a conflict between jquery and bootstrap. 我认为jquery和bootstrap之间存在冲突。 I am pasting my header.php file below for more reference.
我正在粘贴下面的header.php文件以供参考。
header.php header.php文件
<?php require_once "essentials.php";
//error_reporting(~0);
//ini_set('display_errors', 1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--<style>{height:150px; width:1300px;}</style>-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="Public">
<title><?php echo $page_title?></title>
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script src="script_dbafactory.js?<?php echo rand(0,511);?>"></script>
<link href="css/bootstrap.css" rel="stylesheet">
<!--<link href="css/style_header.css" rel="stylesheet">-->
</head>
<body>
<div class="container">
<div class="row clearfix">
<div class="col-md-4 column">
<img alt="logo" src="./images/source.png">
</div>
<div class="col-md-8 column dbf">
<h2>
DBA Factory
</h2>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
<div class="tabbable" id="tabs-775712">
<ul class="nav nav-tabs">
<li>
<a href="../dbafactory/home_page.php?sub=1" data-toggle="tab">Home</a>
</li>
<li>
<a href="../dbafactory/form_page.php?sub=2" data-toggle="tab">Submit a project</a>
</li>
<li>
<a href="../dbafactory/view_table.php?sub=3" data-toggle="tab">All Projects</a>
</li>
<li>
<a href="#panel-4" data-toggle="tab">Innovative Ideas</a>
</li>
<li>
<a href="#panel-5" data-toggle="tab">Matchmaker</a>
</li>
<li>
<a href="#panel-6" data-toggle="tab">Meet the Team</a>
</li>
<div class="dropdown">
<?php include "userlogin.php"; ?>
</div>
</ul>
</div>
</div>
</div>
</div>
</body>
<!--<script type="text/javascript">
//Script to implement tabs
$('#myTab a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
</script>-->
<script>
$.noConflict();
$(document).ready(function (){
$('.dropdown-toggle').dropdown();
$('#userlogin').dropdown('toggle');
});
</script>
Can someone please let me know how do i solve this issue? 有人可以告诉我如何解决这个问题? and how should i load all the js and css files to avoid any issues with the webpage.
我应该如何加载所有的js和css文件,以避免任何网页问题。
Thanks 谢谢
data-toggle="tab" for bootstrap means there has to have a [tab panel] for it, however, you only use it as nav, and it caused the problem. data-toggle =“tab”for bootstrap意味着必须有一个[tab面板],但是,你只能用它作为nav,它会导致问题。
Please read: http://getbootstrap.com/javascript/#tabs 请阅读: http : //getbootstrap.com/javascript/#tabs
Also, use js closure can more easier to avoid js conflict issue: 另外,使用js关闭可以更容易避免js冲突问题:
(function($){
....
})(jQuery);
Please check the code below, you can use WinMerge to compare the code with your own: 请检查下面的代码,您可以使用WinMerge将代码与您自己的代码进行比较:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--<style>{height:150px; width:1300px;}</style>-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="Public">
<title><?php echo $page_title ?></title>
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js" type="text/javascript"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
<!--<link href="css/style_header.css" rel="stylesheet">-->
</head>
<body>
<div class="container">
<div class="row clearfix">
<div class="col-md-4 column">
</div>
<div class="col-md-8 column dbf">
<h2>
DBA Factory
</h2>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
<div class="tabbable" id="tabs-775712">
<ul class="nav nav-tabs">
<li>
<a href="#panel-4">Home</a>
</li>
<li>
<a href="#panel-4">Submit a project</a>
</li>
<li>
<a href="#panel-4">All Projects</a>
</li>
<li>
<a href="#panel-4">Innovative Ideas</a>
</li>
<li>
<a href="#panel-5">Matchmaker</a>
</li>
<li>
<a href="#panel-6">Meet the Team</a>
</li>
<li class="dropdown">
<a id="userlogin" role="button" data-toggle="dropdown" href="#">rdesai<span class="caret"</span></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="userlogin">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Settings</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<script>
(function($){
$(document).ready(function (){
$('.dropdown-toggle').dropdown();
$('#userlogin').dropdown('toggle');
});
})(jQuery);
</script>
</body>
</html>
Usually when i run into jquery and bootstrap conflicts, i just add this as the first line of my php file: 通常当我遇到jquery和bootstrap冲突时,我只是将其添加为我的php文件的第一行:
<script>jQuery.noConflict();</script>
This is to avoid conflicts with other libraries. 这是为了避免与其他库冲突。
You can read more here: https://api.jquery.com/jQuery.noConflict/ 你可以在这里阅读更多内容: https : //api.jquery.com/jQuery.noConflict/
Edit: 编辑:
Or use 或者使用
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.min.js" type="text/javascript"></script>
instead of 1.10.3 而不是1.10.3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.