我已经阅读了很多关于jQuery及其语法的文章.但是我还没有完全理解它的语法,我真的希望对它有更好更深入的理解.
许多文章未能指出简单的语法规则(以及它们所必需的).
截至目前,我遇到了语法理解问题:
我的HTML:
<body>
<a href="http://www.jquery.com" title="anchor1">jQuery.com</a>
<a href="http://www.jquery.com" title="anchor2">jQuery.com</a>
<a href="http://www.jquery.com" title="anchor3">jQuery.com</a>
<!-- JQUERY -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
(function ($) {
// EXAMPLE 1
$("a").each(function () {
console.log(this.title);
});
})(jQuery); // ... everything works fine.
(function ($) {
// EXAMPLE 2
$("a").each(function () {
console.log(this.title);
});
}); // ... missing (jQuery). Why isn't this working?
$(function () { // ... notice the $ at the beginning.
// EXAMPLE 3
$("a").each(function () {
console.log(this.title);
});
}); // ... missing …Run Code Online (Sandbox Code Playgroud)