免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2033 | 回复: 1
打印 上一主题 下一主题

初学jquery [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-01-13 16:22 |只看该作者 |倒序浏览
初学jquery





趁着项目组还没给我分配活,学习点jquery。以后都要用,先学习学习。



jquery是一个javascript库。可以简化javascript 的操作。jquery的口号是:write less ,do more.



这是我写的第一个代码:

jquery1.html

Html代码
  1. <html>  
  2.     <head>  
  3.         <script type = "text/javascript" src = "../jquery/jquery.js"></script>  
  4.         <script type = "text/javascript" src = "1.js"></script>  
  5.     </head>  
  6.     <body>  
  7.         <div id="div1"> click me </div>  
  8.     </body>  
  9. </html>  

  10. <html>
  11.     <head>
  12.             <script type = "text/javascript" src = "../jquery/jquery.js"></script>
  13.                 <script type = "text/javascript" src = "1.js"></script>
  14.         </head>
  15.         <body>
  16.             <div id="div1"> click me </div>
  17.         </body>
  18. </html> 1.js
复制代码
Js代码
  1. $(document).ready(function(){   
  2.     $("div").click(function(){   
  3.         $(this).html(" hello everyone!<br/> the text has change");   
  4.     });   
  5. });  

  6. $(document).ready(function(){
  7.         $("div").click(function(){
  8.                 $(this).html(" hello everyone!<br/> the text has change");
  9.         });
  10. });
复制代码
记得要在本目录的上层目录jquery下引入jquery.js才能使用jquery。



document 是 DOM 对象,使用$(),将document转换成jquery对象。

所有的DOM对象都可以使用$()转换成jquery对象。



在javascript中触发的一般是事件,例如nclick事件,在jquery中一般是函数,如:lick()函数。

$("div" 会获得页面上标签是div的DOM。是一个集合。



所有的jquery函数都是放在这个函数里面。

Js代码
  1. $(document).ready(function(){   
  2.   
  3. --- jQuery functions go here ----   
  4.   
  5. });  

  6. $(document).ready(function(){

  7. --- jQuery functions go here ----

  8. });  $(document).
复制代码
ready()为文档就绪函数。防止在文档在完全加载就绪之前就运行jquery函数,引起错误。





jquery选择器有:
  1.    1.$("p")   选择所有<p>元素。

  2.     2.$("#userName")    选择 id = userName 的第一个元素。id也肯能重复。

  3.     3.$(".userName")     选择 class = userName 的所有元素
复制代码




未完待续...

论坛徽章:
0
2 [报告]
发表于 2012-01-13 16:22 |只看该作者
期待哦
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP