javascript - Bootstrap 警报不起作用

标签 javascript jquery css twitter-bootstrap twitter-bootstrap-2

我正在尝试使用 bootstrap 发出警报,但它不起作用。在 mozilla firebug 控制台中显示

ReferenceError: $ is not defined


$('#openAlert').click(function () {

代码如下。我可以知道缺少什么吗。我包括 jquery 以及 bootstrap js 文件。

<head>
<title>Twilio Messages (Send message Example)</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet">
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="span12">
                <h2>Twilio Messages (Send message Example)</h2>
                <form class="form-signin" action="#Twilio" method="post">
                    <div class="row">
                        <div class="span3">
                            Enter Number to send:
                        </div>
                        <div class="span3">
                            <input type="text" name="toNumber" maxlength="10" placeholder="Enter 10 digits number to send" value="+16822037149"/>
                        </div>
                        <div class="span6">
                            <div class="alert">
                                <button type="button" class="close" data-dismiss="alert">&times;</button>
                                The number to send an SMS to. This field accepts formatted and unformatted US numbers, e.g. +14155551212, (415) 555-1212 or 415-555-1212.<hr />
                                To send message from SandBox Account. The Number has to be <a href="https://www.twilio.com/user/account/phone-numbers/verified" target="_blank">verified</a>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="span3">
                            Enter Message to send:
                        </div>
                        <div class="span3">
                            <textarea name="body" maxlength="160" placeholder="Enter message to send">
                            </textarea>
                        </div>
                        <div class="span6">
                            <div class="alert">
                                <button type="button" class="close" data-dismiss="alert">&times;</button>
                                The text of the message you want to send, limited to 160 characters.
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="span3">
                        </div>
                        <div class="span9">
                            <button class="btn" type="submit" id="openAlert">Send</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>


 <div id="le-alert" class="alert alert-warn alert-block fade">
      <button href="#" type="button" class="close">&times;</button>
      <h4>Alert title</h4>
      <p>Roses are red, violets are blue...</p>
    </div>
    </div>
<script type="text/javascript">
$('#openAlert').click(function () {
      $('#le-alert').addClass('in'); // shows alert with Bootstrap CSS3 implem
    });

    $('.close').click(function () {
      $(this).parent().removeClass('in'); // hides alert with Bootstrap CSS3 implem
    });
</script>

</body>
<script type="text/javascript" src="https://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://getbootstrap.com/2.3.2/assets/js/bootstrap.js"></script>
</html>

最佳答案

将您的脚本包含到 <head></head>然后使用 alert()或者你正在做的任何图书馆调用,

在加载库之前调用库函数

$('#openAlert').click(function () {
      $('#le-alert').addClass('in'); //
.................

应该在*之后*

<script type="text/javascript" src="https://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://getbootstrap.com/2.3.2/assets/js/bootstrap.js"></script>

记住: 您需要先包含 JS 库,然后才能使用函数,因为 $ 是要初始化的

关于javascript - Bootstrap 警报不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19491892/

相关文章:

javascript - 使用 Javascript 创建按钮时如何包含变量?

javascript - 为什么 Proxy 对象反射(reflect)的变化超出了目标对象?

javascript - 文档就绪时调用函数

jquery - 如何拥有清晰、锐利和 slim 的 jqueryUI GUI 元素?

html - 如何在html中向上移动一个按钮

javascript - CSS z-index 无法按预期使用 Angular 动画

javascript - 错误 : [ng:areq] customerController not a function got undefined

javascript - 如何检测浏览器的后退或前进按钮被按下?

javascript - 使用选择标签进行选择后禁用选择?

javascript - 禁用 iframe 的编辑