jquery – 在chrome中使用javascript无法调用bootstrap模态窗口(在firefox中工作)

前端之家收集整理的这篇文章主要介绍了jquery – 在chrome中使用javascript无法调用bootstrap模态窗口(在firefox中工作)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经从twitter-bootstrap中包含了一个模态窗口的示例代码.如果我点击按钮,它会打开模态窗口.但是如果我尝试通过 javascript显示模态窗口,我会收到以下错误
$("#myModal").modal("show")

TypeError: Object [object Object] has no method 'modal'

这个错误只是在chrome中使用,并且在Firefox中使用.

以下是HTML. “project-add-modal”是模态框的id.导航到项目 – >添加看到模态按钮. –

<html class=" js flexBox canvas canvastext no-webgl no-touch geolocation postmessage websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius Boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms no-csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths" lang="en"><!--<![endif]--><head>
    <Meta charset="utf-8">
    <Meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>Project Management</title>
    <Meta name="description" content="">
    <Meta name="author" content="">

    <Meta name="viewport" content="width=device-width">

    <link rel="stylesheet" href="css/style.css">
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <link rel="stylesheet" href="css/bootstrap-responsive.min.css">

      <link rel="stylesheet" href="css/docs.css">

    <script src="//www.google-analytics.com/ga.js"></script><script src="js/libs/modernizr-2.5.3.min.js"></script>
</head>
<body class="">
<div id="header"><div id="top-navbar">
      <div class="navbar navbar-fixed-top">
        <div class="navbar-inner">
          <div class="container">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </a>
            <div class="nav-collapse">
              <ul data-navlinks="left" class="nav">
                <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Projects<b class="caret"></b></a>
                  <ul class="dropdown-menu">
                    <li><a href="#" id="add-new-project" bind="click: pm.client.templating.hello">
                      Add
                    </a></li>
                  </ul>
                </li>
                <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin<b class="caret"></b></a>
                  <ul class="dropdown-menu">
                    <li><a href="#">Invite Users</a></li>
                  </ul>
                </li>
              </ul>
              <ul class="nav pull-right">
                <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Username<b class="caret"></b></a>
                  <ul class="dropdown-menu">
                    <li><a href="#">logout</a></li>
                  </ul>
                </li>
              </ul>
            </div><!-- /.nav-collapse -->
          </div>
        </div><!-- /navbar-inner -->
      </div>
    </div></div>
<div class="container cljs-main"><div id="project-add-section">
<a class="btn" data-toggle="modal" href="#project-add-modal">Launch Modal</a>

      <div class="modal hide fade" id="project-add-modal" style="display: none; ">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">×</button>
          <h3>Add New Project</h3>
        </div>
        <div class="modal-body">
          <form class="form-horizontal">
            <fieldset>
              <div class="control-group">
                <label class="control-label" for="input01">Project Name</label>
                <div class="controls">
                  <input type="text" class="input-xlarge" id="project-name">
                </div>
              </div>
              <div class="control-group">
                <label class="control-label" for="textarea">Project Description</label>
                <div class="controls">
                  <textarea class="input-xlarge" id="project-desc" rows="3"></textarea>
                </div>
              </div>
              <label class="control-label">Invite People to
              collaborate on your project</label>
              <div class="control-group">
                <label class="control-label" for="prependedInput"></label>
                <div class="controls">
                  <div class="input-prepend">
                    <span class="add-on">@</span><input class="span2" id="prependedInput" size="16" type="text">
                  </div>
                  <p class="help-block">Here's some help text</p>
                </div>
              </div>
            </fieldset>
        </form></div>
        <div class="modal-footer">
          <a href="#" class="btn" data-dismiss="modal">Close</a>
          <a href="#" class="btn btn-primary">Save changes</a>
        </div>
      </div>

    </div></div>
<footer>

</footer>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.2.min.js"><\/script>')</script>

<!-- scripts concatenated and minified via ant build script-->
<script src="js/bootstrap.min.js"></script>
<script src="js/plugins.js"></script>
<script src="js/script.js"></script>
<script src="cljs/client.js"></script><script type="text/javascript" src="deps.js"></script>
<script>$(function() {cljsbinding.boot()})</script>
<!-- end scripts-->


<script>
    var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
    (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
    g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
    s.parentNode.insertBefore(g,s)}(document,'script'));
</script>




<iframe name="xpcpeer7X7y" id="xpcpeer7X7y" style="display: none; " src="http://localhost:9000/repl?xpc=%7B%22cn%22%3A%22PmCIncJdVC%22%2C%22tp%22%3Anull%7D"></iframe></body></html>

谢谢,
穆尔塔扎

解决方法

我注意到这个问题可能会在jquery加载两次时发生.

单独的twitter引导插件加载在bootstrap.js之上

.js文件错误的顺序包含

错误的类型被发送到该功能.

猜你在找的jQuery相关文章