jQuery不适用于新手
jQuery not working for a newbie
我在这里使用bob-tabors-jQuery视频教程已经有很长一段时间了,我无法让jQuery工作。
这是我的html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" type="text/css" href="main.css" />
<title>14. Getting Started with jQuery</title>
</head>
<body>
<h1 id="title">14. Getting Started with jQuery</h1>
<p id="first">
<span>Now is the time for all good men to come to
the aid of their country.</span>
</p>
<p id="second">
<strong>In the end these things matter most:
How well did you love? How fully did you live?</strong>
</p>
<p id="third">
<a id="myAnchor" href="http://www.learnvisualstudio.net">Visit my website</a>
</p>
</body>
</html>
这是我的js
jQuery(document).ready(function() {
alert("thsdjasl");
}
但在html之后,就没有警报了。
您缺少就绪函数的右括号:
jQuery(document).ready(function() {
alert("thsdjasl");
});
如果没有这个,你的警报将不会运行,你将得到以下错误:
未捕获的SyntaxError:意外的令牌}
您缺少一个右括号和分号。理想情况下,您应该为文档准备好的部分使用"$"命名法:
$(document).ready(function() {
alert("thsdjasl");
});
最后,您可以通过在浏览器中打开开发人员工具(Chrome很好),转到javascript源选项卡,查找弹出的错误和警告,自己解决这个问题。
确保jquery.js文件位于根目录中。并使用这个:
$(document).ready(function(){
console.log('bla bla ');
alert('bla');
});
相关文章:
- JQueryhide()不适用于Mozzilla,但适用于Chrome
- PHP中的setcookie仅适用于localhost
- html5 drawImage适用于firefox,而不是chrome
- 提供“;onClick"适用于iPad(触摸屏)和桌面用户的默认功能
- jQuery表单验证适用于Mozilla和Internet Explorer,但不适用于Chrome或Safari
- ResolveUrl是否适用于././也
- Firebase updateChildValues适用于IOS,但不适用于Web和Android
- JavaScript警报适用于int,但不适用于string
- SQLite插件适用于Mac和Windows,但不适用于手机上的Safari
- Regex Replace仅适用于Last Match
- window.onload适用于aspx页面,但不适用于普通html
- Jquery Ajax POST不工作.适用于GET
- 画布上的自定义字体仅适用于safari
- Javascript仅适用于alert()和Debug模式
- JS适用于Firefox和Safari,但不适用于Chrome.此处'是我的网站
- Regex不适用于Firefox,但适用于Chrome
- 通过单击主菜单外部关闭子菜单'不适用于IE,但适用于Firefox&铬
- AngularJS$http.post没有'不适用于Chrome,仅适用于IE
- Javascript仅适用于jQuery mobile中的页面刷新
- 关闭当前选项卡并打开一个新的-仅适用于Chrome