Jquery 复习练习

window.onload = function() {} == $(function() {});

千万注意:js对象和jq对象的区别,这也是常常犯的错误

js对象举例:

window.onload=function()
{
var a = document.getElementById("shang");
a.style.backgroundColor = "#F00";
}

jq对象举例:

 $(function()
{
var a=$("#shang");
a.css("background-color","#F00");
});
   <script type="text/javascript">
//js写法
window.onload = function () {
var a = document.getElementsByTagName("input");
a[0].onclick = function() {
var s = document.getElementById('shang');
s.style.backgroundColor="red";
}
}
//jq写法
$(function () {
var a = $("input");
a.click(function () {
var s = $("shang");
s.css("background-color", "red");
}); }); </script>

<body>
<input type="button" value="dianji"/>
<div id="shang">dddds</div>
</body>

css 复杂选择

   <script type="text/javascript">
$(function() {
$("input").click(function() {
$("#shang ul li span").css("background-color", "red");
});
}); </script>
</head>
<body>
<input type="button" value="dianji"/>
<div id="shang">dddds
<ul>
<li>fasl</li>
<li> sssss<span> span hong</span></li>
</ul>
</div>
</body>
<input id="zhang" type="button" value="zhang" /><br />

  (function(w) { })(window);
(function(w) { var getE= function(id) { return document.getElementById(id);
}
w.getE = getE; })(window); var a = getE("zhang").value;
$("#zhang").bind("click", function(event) { alert(a);});
</script>
<!DOCTYPE html>
<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.8.3.js"></script>
</head>
<body>
<div id="divMsg">Hello World!</div>
<input id="btnShow" type="button" value="显示"/>
<input id="btnHide" type="button" value="隐藏"/><br/>
<input id="btnChange" type="button" value="修改内容为 Hello World, too!"/>
<div id="testDiv">测试图层</div>
<input id="btnzhaoren" type="button" value="zhaoren"/><br/>
<input id="zhang" type="button" value="zhang" /><br />
<script type="text/javascript">
$("#btnShow").bind("click", function (event) { $("#divMsg").show(); });
$("#btnHide").bind("click", function (event) { $("#divMsg").hide(); });
$("#btnChange").bind("click", function (event) { $("#divMsg").html("我要杀了你!") });
$("#btnHide").bind("click", function (event) { $("#testDiv").each(function () { $("#testDiv").html("谁是小三") }); }); //$("#testDiv").each(function () { alert(this); }); (function(w) { })(window);
(function (w)
{
var tools={
getE: function (id) { return document.getElementById(id); },
iSIE: function(className) {}
} w.t = tools; })(window); var a = t.getE("zhang").value; $("#zhang").bind("click", function(event) { alert(a);});
</script>
</body> </html>

js高级用法

<!DOCTYPE html>
<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.8.3.js"></script>-->
<script src="jquery-1.4.2.js"></script> <script type="text/javascript">
window.onload = function () {
d.tab("shang","xia");
}
</script>
<style type="text/css">
*{ margin: 0px;padding: 0px;}
#shang{ width: 800px;height: 30px;}
#shang ul li{ width: 100px;background-color: aquamarine;float: left;margin-left: 1px;}
#xia{ width: 800px;height: 400px;}
#xia ul li{ width: 800px;height: 400px;display:none;background-color: #960;}
</style>
</head>
<body>
<div id="shang">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
<div id="xia">
<ul>
<li style="display: block">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div> <script type="text/javascript">
(function (w) {
var tools =
{
getE: function (id) { return document.getElementById(id); },
getClass: function (classname) { return document.getElementsByClassName(classname); }
}
var dong =
{
tab: function (id1, id2) {
var s = tools.getE(id1);
var x = tools.getE(id2);
var sarr = s.getElementsByTagName("li");
var xarr = x.getElementsByTagName("li"); for (var i = 0; i < sarr.length; i++)
{
sarr[i].onclick = (function (num)
{ return function()
{ for (var b = 0; b < xarr.length; b++)
{ xarr[b].style.display = 'none';
} xarr[num].style.display = "block";
}
})(i);
}
},
leftRight: function () { }
}
w.t = tools;
w.d = dong; })(window); </script> </body>
</html>

最新文章

  1. POST和GET区别
  2. atitit.获取北京时间CST 功能api总结 O7
  3. Android布局_网格布局GirdLayout
  4. BestCoder Round #65 hdu5590(水题)
  5. [转]NHibernate之旅(3):探索查询之NHibernate查询语言(HQL)
  6. c#geckofx文件流下载
  7. C#多态联系之虚方法
  8. 服务器是windows时tomcat无法打印所有日志配置修改
  9. HaoZip(好压) 去广告纯净版 4.4
  10. linux 在jetty中部署web工程
  11. django 实现同一个ip十分钟内只能注册一次
  12. C++ enum用法小技巧
  13. linux所有命令不能用显示-bash: ls: command not found
  14. shell练习题4
  15. 修改spring源码重写classloader实现项目加密
  16. eclipse显示代码行数
  17. 【论文笔记】Spatial Temporal Graph Convolutional Networks for Skeleton-Based Action Recognition
  18. Servlet模板,一个供新手参考的模板
  19. 2.选择元素 - 自定义过滤器《jquery实战》
  20. MaximumClique HDU1530

热门文章

  1. Canvas 唯美雨落代码实现
  2. IP地址的分类与寻址
  3. php 执行的目录到新的 directory 目录中
  4. 20145337实验四Android开发基础
  5. Struts2的Action(二)
  6. php实现实现代码多主从,切换,轮询,健康检查
  7. jQuery 控制表单和表格
  8. The index also can be used for LIKE comparisons if the argument to LIKE is a constant string that does not start with a wildcard character.
  9. Python之什么是函数
  10. js中eval() 方法的使用以及一些特殊的使用方式