<script type=“text/javascript” src=“xxx//jquery-x.y.z.js">
引入jQuery.存在两个版本,jquery-x.y.z.min.js是精简压缩版,不带min的是开发版,代码中的注释和缩进等都被保留了.
<html> <head> <title>Hello jQuery</title> <script type="text/javascript" src="libs//jquery-1.11.2.js"></script> <script type="text/javascript"> $(document).ready(function () { alert("Hello World"); }); </script> </head> <body> </body> </html>
window.onload = sayHello; window.onload = sayWorld; function sayHello() { alert("Hello"); } function sayWorld() { alert("World"); }
$(document).ready(sayHello); $(document).ready(sayWorld); function sayHello() { alert("Hello"); } function sayWorld() { alert("World"); }
<body> <a href="#">test1</a><br> <a href="#">test2</a><br> <a href="#">test3</a><br> <a href="#">test4</a> </body>
window.onload = function () { var myLinks = document.getElementsByTagName("a"); for(var i = 0; i < myLinks.length; ++i){ myLinks[i].onclick = function(){ alert("Hello link: " + i); } } }
$(document).ready(function () { $("a").click(function () { alert("Hello link from jQuery!"); }); });
<p id="clickMe">Click Me!</p>
//Part 1: DOM --> jQuery //DOM object: var pElement = document.getElementsByTagName("p")[0]; alert("DOM pElement: " + pElement.innerHTML); //Convert DOM object to jQuery object: var pElementjQuery = $(pElement); alert("jQuery pElementjQuery: " + pElementjQuery.html());
//Part 2: jQuery --> DOM //jQuery object array: var clickMejQuery = $("#clickMe"); //Convert jQuery object to DOM object (2 ways): //way 1: var domClickMe1 = clickMejQuery[0]; alert("dom1: " + domClickMe1.innerHTML); //way 2: var domClickMe2 = clickMejQuery.get(0); alert("dom2: " + domClickMe2.innerHTML);
原文:http://www.cnblogs.com/mengdd/p/4201746.html