一些小例子

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
   
<script type="text/javascript" src=jquery-1.3.1.js></script> 
   
<style type="text/css">
#menu 
{ 
    width
:300px; 
}
.has_children
{
    background 
: #555;
    color 
:#fff;
    cursor
:pointer;
}
.highlight
{
    color 
: #fff;
    background 
: green;
}
div
{
    padding
:0;
}
div a
{
    background 
: #888;
    display 
: none;
    float
:left;
    width
:300px;
}
</style>
<script type="text/javascript">
$(
function(){
//children()子节点集合
//
siblings()同级的相同节点集合
    $("div.has_children").click(function(){
        $(
this).addClass("highlight").children("a").show().end().siblings().removeClass("highlight").children("a").hide();
    });
})
</script>
</head>
<body>
    
<form id="form1" runat="server">
<div id="menu">
    
<div class="has_children">
        
<span>第1章-认识jQuery</span>
        
<a>1.1-JavaScript和JavaScript库</a>
        
<a>1.2-加入jQuery</a>
        
<a>1.3-编写简单jQuery代码</a>
        
<a>1.4-jQuery对象和DOM对象</a>
        
<a>1.5-解决jQuery和其它库的冲突</a>
        
<a>1.6-jQuery开发工具和插件</a>
        
<a>1.7-小结</a>
    
</div>
    
<div class="has_children">
        
<span>第2章-jQuery选择器</span>
        
<a>2.1-jQuery选择器是什么</a>
        
<a>2.2-jQuery选择器的优势</a>
        
<a>2.3-jQuery选择器</a>
        
<a>2.4-应用jQuery改写示例</a>
        
<a>2.5-选择器中的一些注意事项</a>
        
<a>2.6-案例研究——类似淘宝网品牌列表的效果</a>
        
<a>2.7-还有其它选择器么?</a>
        
<a>2.8-小结</a>
    
</div>
    
<div class="has_children">
        
<span>第3章-jQuery中的DOM操作</span>
        
<a>3.1-DOM操作的分类</a>
        
<a>3.2-jQuery中的DOM操作</a>
        
<a>3.3-案例研究——某网站超链接和图片提示效果</a>
        
<a>3.4-小结</a>
    
</div>
</div>
<script type="text/javascript">
$(
function(){
    
//table中最后一个td中的checkbox如果选中 修改背景颜色
    $("#table1>tbody>tr:has(td:last:has(:checkbox:enabled))").css("background","red");
   
//is()方法
    $("#Checkbox3").click(function(){
        
if($(this).is(":checked"))
       alert(
"aaa"+$(this).attr("checked")); 
    });   
   }); 
})
</script>
<table id="table1" width="500"><tbody><tr><td>
    111
</td><td>
    
<input id="Checkbox1" type="checkbox" checked="checked" /></td></tr>
<tr><td>
    222
</td><td>
    
<input id="Checkbox2" type="checkbox" /></td></tr></tbody></table>
    
<input id="Checkbox3" type="checkbox" />
    
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
   
<style type="text/css">
 *
{ margin:0; padding:0;}
body 
{font-size:12px;text-align:center;}
{ color:#04D; text-decoration:none;}
a:hover 
{ color:#F50; text-decoration:underline;}
.SubCategoryBox 
{width:600px; margin:0 auto; text-align:center;margin-top:40px;}
.SubCategoryBox ul 
{ list-style:none;}
.SubCategoryBox ul li 
{ display:block; float:left; width:200px; line-height:20px;}
.showmore 
{ clear:both; text-align:center;padding-top:10px;}
.showmore a 
{ display:block; width:120px; margin:0 auto; line-height:24px; border:1px solid #AAA;}
.showmore a span 
{ padding-left:15px; background:url(img/down.gif) no-repeat 0 0;}
.promoted a 
{ color:#F50;}
</style> 
<script src=jquery-1.3.1.js></script>
</head>
<body>
    
<form id="form1" runat="server">
<div class="SubCategoryBox">
    
<ul>
        
<li ><href="#">佳能</a><i>(30440) </i></li>
        
<li ><href="#">索尼</a><i>(27220) </i></li>
        
<li ><href="#">三星</a><i>(20808) </i></li>
        
<li ><href="#">尼康</a><i>(17821) </i></li>
        
<li ><href="#">松下</a><i>(12289) </i></li>
        
<li ><href="#">卡西欧</a><i>(8242) </i></li>
        
<li ><href="#">富士</a><i>(14894) </i></li>
        
<li ><href="#">柯达</a><i>(9520) </i></li>
        
<li ><href="#">宾得</a><i>(2195) </i></li>
        
<li ><href="#">理光</a><i>(4114) </i></li>
        
<li ><href="#">奥林巴斯</a><i>(12205) </i></li>
        
<li ><href="#">明基</a><i>(1466) </i></li>
        
<li ><href="#">爱国者</a><i>(3091) </i></li>
        
<li ><href="#">其它品牌相机</a><i>(7275) </i></li>
    
</ul>
    
<div class="showmore">
        
<href="more.html"><span>显示全部品牌</span></a>
    
</div>
</div>
<script type="text/javascript">
$(
function(){
    
//索引大于5 最后一个除外
    var hh= $("ul li:gt(5):not(:last)");
    hh.hide(); 
    $(
"div.showmore>a").click(function(){
        
if(hh.is(":visible"))//如果是显示的
       {
            hh.hide();
            $(
".showmore a span").css("background","url(img/down.gif)  no-repeat 0 0").text("显示全部品牌");
             
//筛选
            $("ul li").filter(":contains('宾得'),:contains('索尼')").removeClass("promoted");
       }
else
       {
            hh.show();
            $(
".showmore a span").css("background","url(img/up.gif)  no-repeat 0 0").text("精简显示品牌");
           $(
"ul li").filter(":contains('宾得'),:contains('索尼')").addClass("promoted");
       }
       
return false
    });
})
</script>
    
</form>
</body>
</html>


 

posted @ 2009-12-17 16:19  melody&amp;amp;amp;bobo  阅读(178)  评论(0编辑  收藏  举报