分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

jQuery选择器

发布时间:2023-09-06 02:05责任编辑:沈小雨关键词:jQuery选择器

<!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> <link rel="stylesheet" type="text/css" href="css/default.css" /> <!-- 引入jQuery --><script src="../../scripts/jquery.js" type="text/javascript"></script><script type="text/javascript">$(function(){ ????????????????????????????????????// ?等待DOM加载完毕. ???var $category = $(‘ul li:gt(5):not(:last)‘); ????????????// ?获得索引值大于5的品牌集合对象(除最后一条) ???????$category.hide(); ???????????????????????????????// ?隐藏上面获取到的jQuery对象。 ???var $toggleBtn = $(‘div.showmore > a‘); ????????????// ?获取“显示全部品牌”按钮 ???$toggleBtn.click(function(){ ?????????if($category.is(":visible")){ ???????????????$category.hide(); ???????????????????????????// ?隐藏$category ???????????????$(this).find(‘span‘) ???????????????????.css("background","url(img/down.gif) no-repeat 0 0") ?????????????????????????.text("显示全部品牌"); ?????????????????//改变背景图片和文本 ???????????????$(‘ul li‘).removeClass("promoted"); ???????????// 去掉高亮样式 ?????????}else{ ???????????????$category.show(); ???????????????????????????// ?显示$category ???????????????$(this).find(‘span‘) ???????????????????.css("background","url(img/up.gif) no-repeat 0 0") ?????????????????????????.text("精简显示品牌"); ?????????????????//改变背景图片和文本 ???????????????$(‘ul li‘).filter(":contains(‘佳能‘),:contains(‘尼康‘),:contains(‘奥林巴斯‘)") ???????????????????.addClass("promoted"); ???????????????//添加高亮样式 ?????????} ???????return false; ?????????????????????????????//超链接不跳转 ???})})</script></head><body><div class="SubCategoryBox"><ul><li ><a href="#">佳能</a><i>(30440) </i></li><li ><a href="#">索尼</a><i>(27220) </i></li><li ><a href="#">三星</a><i>(20808) </i></li><li ><a href="#">尼康</a><i>(17821) </i></li><li ><a href="#">松下</a><i>(12289) </i></li><li ><a href="#">卡西欧</a><i>(8242) </i></li><li ><a href="#">富士</a><i>(14894) </i></li><li ><a href="#">柯达</a><i>(9520) </i></li><li ><a href="#">宾得</a><i>(2195) </i></li><li ><a href="#">理光</a><i>(4114) </i></li><li ><a href="#">奥林巴斯</a><i>(12205) </i></li><li ><a href="#">明基</a><i>(1466) </i></li><li ><a href="#">爱国者</a><i>(3091) </i></li><li ><a href="#">其它品牌相机</a><i>(7275) </i></li></ul><div class="showmore"><a href="more.html"><span>显示全部品牌</span></a></div></div></body></html>

 

jQuery选择器

原文地址:https://www.cnblogs.com/i-shanghai/p/9349580.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved