jQuery/JSON

来源:互联网 发布:按网络功能层次分 编辑:程序博客网 时间:2024/06/06 07:29

1,导航栏:点击显示

<!-- 引入 jQuery --><script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script><script type="text/javascript">//等待dom元素加载完毕.$(document).ready(function(){$(".***has_children***").click(function(){    $(this).addClass("highlight")          //为当前元素增加highlight类        .children("a").show().end()         //将子节点的a元素显示出来并重新定位到上次操作的元素    .siblings().removeClass("highlight")        //获取元素的兄弟元素,并去掉他们的highlight类        .children("a").hide();              //将兄弟元素下的a元素隐藏});});</script>

2,单选框勾选,alert“感谢你的支持!你可以继续操作”
DOM:

<script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script><script type="text/javascript">//等待dom元素加载完毕.$(document).ready(function(){var $cr = $("#cr");  //jQuery对象var cr = $cr.get(0); //DOM对象,获取 $cr[0]$cr.click(function(){    if(cr.checked){ //DOM方式判断        alert("感谢你的支持!你可以继续操作!");    }})});</script>

jQuery:

<script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script><script type="text/javascript">//等待dom元素加载完毕.$(document).ready(function(){var $cr = $("#cr");  //jQuery对象$cr.click(function(){    if($cr.is(":checked")){ //jQuery方式判断        alert("感谢你的支持!你可以继续操作!");    }})});</script>

3,window.onload

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript">function t(){alert("test1")}function b(){alert("test2")}window.onload =t ;window.onload =b ;</script>

页面执行alert(“test2”)

4,顺序加载

<!-- 引入 jQuery --><script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script><script type="text/javascript">//等待dom元素加载完毕.$(document).ready(function(){alert("Hello World!");});//test2$(document).ready(function(){alert("Hello again!");});</script>

输出:alert(“Hello World!”);alert(“Hello again!”);

5,

<!-- 引入 jQuery --><script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script><script type="text/javascript">//等待dom元素加载完毕.$(document).ready(function(){var domObj = document.getElementsByTagName("h3")[0]; // Dom对象var $jQueryObj = $(domObj);  //jQuery对象alert("***DOM对象:***"+domObj.innerHTML);alert("***jQuery对象:***"+$jQueryObj.html());});</script></head><body><h3>***例子***</h3><p title="选择你最喜欢的水果." >你最喜欢的水果是?</p><ul><li>苹果</li><li>橘子</li><li>菠萝</li></ul></body>

输出:DOM对象:例子
jQuery对象:例子

0 0
原创粉丝点击