Javascript 引导警报不工作
我正在尝试使用引导程序发出警报,而不是wokring。在mozilla firebug控制台中显示Javascript 引导警报不工作,javascript,jquery,css,twitter-bootstrap,twitter-bootstrap-2,Javascript,Jquery,Css,Twitter Bootstrap,Twitter Bootstrap 2,我正在尝试使用引导程序发出警报,而不是wokring。在mozilla firebug控制台中显示 ReferenceError: $ is not defined $('#openAlert').click(function () { 代码如下。我可以知道缺少了什么。我包括jquery和引导js文件 <head> <title>Twilio Messages (Send message Example)</title> <meta http-eq
ReferenceError: $ is not defined
$('#openAlert').click(function () {
代码如下。我可以知道缺少了什么。我包括jquery和引导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">×</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">×</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">×</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>
您需要包括对jQuery的脚本引用
<script src="scripts/jquery.js">
您忘记了bootstrap.js之前的jQuery添加头:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
将脚本包括到,然后使用alertor或您正在进行的任何库调用
当您在加载库之前调用库函数时
$('#openAlert').click(function () {
$('#le-alert').addClass('in'); //
.................
应该是*之后*
请记住:首先需要包含JS库,然后才能使用函数,因为要初始化$s对jQuery文件的引用需要放在使用$s函数的脚本之前 通过将所有js放在底部,您几乎做到了这一点 但是,您需要确保在尝试使用jQuery文件之前先引用它 确保在代码中导入了jQuery插件 在使用包装内部文档处理程序函数之前,请确保已加载jQuery插件。 验证jQuery是否已加载的最简单检查是
if (typeof jQuery != 'undefined') {
// do operation's here
}
或
这应该起作用:
<div id="le-alert" class="alert alert-warn alert-block fade">
<button href="#" type="button" class="close">×</button>
<h4>Alert title</h4>
<p>Roses are red, violets are blue...</p>
</div>
</div>
<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>
<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>
</html>
在调用任何基于jquery的jquery依赖项和自定义函数之前,请确保包含jquery。确保使用正确的path@ubercooluk这是代码。jquery.com/jquery.min.js>那是哪里…?我不能see@ubercooluk虽然我已经得到了答案,但你的答案也很有用,所以+1I你的问题没有被否决。被否决的人一定认为你的问题是无知。
if (window.jQuery) {
// jQuery is available.
}
<div id="le-alert" class="alert alert-warn alert-block fade">
<button href="#" type="button" class="close">×</button>
<h4>Alert title</h4>
<p>Roses are red, violets are blue...</p>
</div>
</div>
<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>
<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>
</html>