jquery和bootstrap之间的冲突 [英] Conflict between jquery and bootstrap

查看:60
本文介绍了jquery和bootstrap之间的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码,我在header.php中包含jquery文件和bootstrap文件。我遇到的问题是,如果我在bootstrap.js文件之前包含jquery文件,它会弄乱我的网页上的其他选项卡,基本上即使我点击其他选项卡它也不会导航我。

I have a code where I am including jquery files and bootstrap files in the header.php. 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.

我认为jquery和bootstrap之间存在冲突。我正在粘贴下面的header.php文件以供参考。

I think there is a conflict between jquery and bootstrap. I am pasting my header.php file below for more reference.

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>

有人可以告诉我如何解决这个问题?我应该如何加载所有的js和css文件,以避免任何网页问题。

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.

谢谢

推荐答案

data-toggle =tabfor bootstrap意味着它必须有一个[选项卡面板],但是,你只能用它作为导航,它会导致问题。

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.

请阅读: http://getbootstrap.com/javascript/#tabs

另外,使用js闭包可以更容易避免js冲突问题:

Also, use js closure can more easier to avoid js conflict issue:

(function($){
    ....
})(jQuery);

请检查下面的代码,您可以使用WinMerge将代码与您自己的代码进行比较:

Please check the code below, you can use WinMerge to compare the code with your own:

<!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>

这篇关于jquery和bootstrap之间的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆