jQuery系列01---jQuery简介、jQuery使用详解、DOM对象与jQuery对象的转换与区别

1.jQuery优秀的Javascrīpt框架。官方网站jquery.com,可以下载压缩的或者开发版的jQuery。

2.下面是一些入门程序,通过程序学jQuery。

01

<!DOCTYPE html>
<html>
  <head>
    <title>MyHtml.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="jquery-1.7.1.js"></script>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<script type="text/javascript">
				//ready 方法的作用是当页面中的dom加载完毕后执行参数中的函数
				$(document).ready(function() {
					alert("hello world");	
				});
		</script>
  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
</html>

02
<!DOCTYPE html>
<html>
  <head>
    <title>MyHtml.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="jquery-1.7.1.js"></script>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<script type="text/javascript">
				//ready 方法的作用是当页面中的dom加载完毕后执行参数中的函数
				$(document).ready(function() {
					alert("hello world");	
				});
		</script>
  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
</html>

03
 <!DOCTYPE html>
<html>
  <head>
    <title>MyHtml.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="jquery-1.7.1.js"></script>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<script type="text/javascript">
		$(document).ready(function(){
			alert("hello");	
			
		});
		$(document).ready(function(){
			alert("world");	
		});		
		</script>
  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
</html>
04
 <!DOCTYPE html>
<html>
  <head>
    <title>MyHtml.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<script type="text/javascript">
			window.onload = function() {
				var myLinks = document.getElementsByTagName("a");
				for (var i = 0; i < myLinks.length; i++) {
					myLinks[i].onclick = function() {
						alert("hello world");	
					}
				}
			}
				
		</script>
  </head>
  
  <body>
    <a href="#">test1</a><br>
    <a href="#">test2</a><br>
    <a href="#">test3</a><br>
    <a href="#">test4</a><br>
    <a href="#">test5</a><br>
  </body>
</html>

04 - 1
 <!DOCTYPE html>
<html>
  <head>
    <title>MyHtml.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="jquery-1.7.1.js"></script>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<script type="text/javascript">
			$(document).ready(function(){
				$("a").click(function(){
					alert("hello world");	
				});	
			});	
		</script>
  </head>
  
  <body>
    <a href="#">test1</a><br>
    <a href="#">test2</a><br>
    <a href="#">test3</a><br>
    <a href="#">test4</a><br>
    <a href="#">test5</a><br>
  </body>
</html>

05
 <!DOCTYPE html>
<html>
  <head>
    <title>MyHtml.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="jquery-1.7.1.js"></script>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<script type="text/javascript">
			$(document).ready(function (){
				var pElement = document.getElementsByTagName("p")[0];	
				//将DOM对象转换为jQuery对象
				var pElementjQuery = $(pElement);
				//alert("DOM 对象的结果:" + pElement.innerHTML);
				//alert("jQuery 对象的结果:" + pElementjQuery.html());
				var cm = $("#clickMe");//获得的是JQuery对象
				
				//jQuery对象转换为DOM对象(第一种方式)			
				var t = cm[0];//t是DOM对象	
				alert(t.innerHTML);
				//jQuery对象转换为DOM对象(第二种方式)
				var s = cm.get(0);
				alert(s.innerHTML);
			});
		</script>
  </head>
  
  <body>
    <p id="clickMe">点击我</p>
  </body>
</html>

简单的几个例子。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值