1. 使用JQ时需要先引用 JQ 包; 其他的JQ代码 需要写在 引用标签的下面如下图[基本格式]

JQ中 是纯代码  没有判断 没有循环   如果 有 时间间隔和延迟  则使用JS 代码

  详见 下面例题

因为代码 放在最后  所以 JQ 可以加$(document).ready 也可以不加

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-1.11.2.min.js"></script>
<style type="text/css">
.aa{ width:200px; height:200px; float:left; margin:5px; background-color:#3F6}
</style>
</head> <body> <div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div> <input type="button" value="测试" onclick="test()" /> </body> <script type="text/javascript">
$(document).ready(function(){
$(".aa").click(function(){
//所有元素背景色变成原来的
$(".aa").removeAttr("xz");
$(".aa").css("background-color","#3F6");
//找到点击了谁
$(this).attr("xz","1");
$(this).css("background-color","red");
}) $(".aa").mousemove(function(){
//所有元素背景色变成原来的
$(".aa").css("background-color","#3F6");
//找到点击了谁
$(this).css("background-color","yellow");
$("[xz='1']").css("background-color","red");
}) })
</script> </html>

有$(document)

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-1.11.2.min.js"></script>
<style type="text/css">
.aa{ width:200px; height:200px; float:left; margin:5px; background-color:#3F6}
</style>
</head> <body> <div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div>
<div class="aa">
</div> <input type="button" value="测试" onclick="test()" /> </body> <script type="text/javascript"> $(".aa").click(function(){
//所有元素背景色变成原来的
$(".aa").removeAttr("xz");
$(".aa").css("background-color","#3F6");
//找到点击了谁
$(this).attr("xz","1");
$(this).css("background-color","red");
}) $(".aa").mousemove(function(){
//所有元素背景色变成原来的
$(".aa").css("background-color","#3F6");
//找到点击了谁
$(this).css("background-color","yellow");
$("[xz='1']").css("background-color","red");
}) </script> </html>

无$(document)

2.JQ中得查找方法   找出来的 都是JQUARY对象(数组形式存在)   0号索引位置  为  dom对象 

找元素,Jquery对象
var b = $("#aa"); //根据ID找
alert(b[0]); var b = $(".aa"); //根据class找
alert(b[1]); //找到的是DOM对象
alert(b.eq(1)); //找到的是Jquery对象 var b = $("div"); //根据标签名找
alert(b[0]); var b = $("[id='aa']"); //根据属性找
alert(b[0]);

3.JQ 操作内容

			非表单元素
b.html(); //操作元素里面的HTML代码
b.html("<span style='color:red'>文字</span>");
b.text(); //操作元素里面的文本
b.text("文字"); 表单元素 (添加value值)
b.val("hello");

4. 操作属性

			设置属性
b.attr("bs","test");
获取属性
alert(b.attr("aa"));
移除属性
b.removeAttr("aa");
checkbox 属性 使用下面的修改方式 避免重复(因为原文中有默认属性)
b.prop("checked",false);

5.JQ的 方法可以获取内嵌中的样式JS操作 只可以获取 内联中的样式

           设置内嵌中样式: b.css("background-color","red");
获取内嵌中得样式:alert(b.css("width"));
alert(b.css("background-color"));

6.bind  绑定函数

$("body").unbind("mousemove");
$("body").bind("mousemove",function(e){});

  

最新文章

  1. 浅析“依赖注入(DI)/控制反转(IOC)”的实现思路
  2. RestEasy 3.x 系列之三:jsonp
  3. 几个简单的js正则验证
  4. csuoj 1505: 酷酷的单词
  5. SpringMVC学习系列(10) 之 异常处理
  6. 使用Objective-C的文档生成工具
  7. mysql 截取字符
  8. UIBezierPath
  9. 世纪互联、微软Azure与无穷小微积分
  10. Android自己主动化測试——CTS測试
  11. Linux Shell 1 - Print from terminal
  12. 【1414软工助教】团队作业4——第一次项目冲刺(Alpha版本) 得分榜
  13. Mysql 启动遇到 The server quit without updating PID file (/[FAILED]l/mysql/data/021rjsh216086s.pid)和Attempted to open a previously opened tablespace
  14. 【老司机经验】CC2530&amp;STM8S105二合一嵌入式学习板设计思路与经验分享
  15. spring 相关注解详情(一)
  16. SoapUI 请求 https 报 javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
  17. 1.7Oo局部变量和成员变量执行顺序
  18. php图片上传base64数据编码。
  19. Haskell语言学习笔记(81)Data.Typeable
  20. jQuery通用的全局遍历方法$.each()用法实例

热门文章

  1. Web App 压力测试
  2. Java学习笔记(三)
  3. 两种遍历list
  4. Leetcode 55. Jump Game
  5. 【BZOJ-4245】OR-XOR 按位贪心
  6. NTFS交换数据流隐写的应用
  7. 【总结】.Net面试题集锦 (二)
  8. 解决Python中不能输入汉字的问题
  9. The commands of Disk
  10. Spring-----定时任务Quartz配置之手动设置