一款简单,常用的切换(点击按钮,切换内容)

 1 <div class="list_shop">
 2        <p>保障期限 1年</p>
 3     <ul class="shop_click">
 4            <li class="red">A款</li>
 5            <li>B款</li>
 6        </ul>
 7
 8        <p><a href="">立即购买</a></p>
 9
10 </div>
11
12 <div class="shop_all">
13     <div class="shop_all_a" style="display:block;">
14         111111111
15     </div>
16
17     <div class="shop_all_a" style="display:none;">
18         2222222
19     </div>
20 </div>
 1 <style type="text/css">
 2  *{margin:0px; padding:0px;}
 3   a{ text-decoration:none; }  ul{list-style:none;}
 4  .shop_all{width:300px; height:300px; overflow: hidden;}
 5  .shop_all_a{width:300px; height:300px; background:pink;}
 6  .list_shop{width:1000px; overflow: hidden; margin:auto;}
 7  .list_shop p{width:200px; height:30px; line-height:30px;}
 8  .shop_click{width:500px; overflow: hidden;}
 9  .shop_click li{width:100px; height:40px; border:1px solid red; margin:0px 10px; text-align:center; line-height:40px; float:left; cursor:pointer;}
10 .red{background:red; color:#fff;}
11 </style>
<script>
    $(function(){
        $(‘.shop_click li‘).click(function(){
           $(this).addClass(‘red‘).siblings().removeClass(‘red‘)//找到“red”类  找到每个div的所有同辈元素  从匹配的元素中删除 ‘red‘ 类//
           $(‘.shop_all_a‘).eq($(this).index()).show().siblings().hide(); //获取这个匹配的元素 显示它  同类的元素隐藏//
       })
    })
</script>

这是一款简单,易用的切换,使用范围非常广,jquery代码也非常好理解,大家要学会举一反三,直接复制代码,运行后即可看到效果~~~~

时间: 2024-07-28 15:03:16

一款简单,常用的切换(点击按钮,切换内容)的相关文章

初识安卓小程序(点击按钮切换屏幕颜色)

如图,点击按钮就会切换屏幕的颜色 首先,先创建一个安卓项目(我的版本是4.4.2的),名字为"world",当然,也可以别的名称 然后在res文件夹下找到layout文件夹,找到activity_main.xml或fragment_main.xml,在里面输入或拖拽按钮 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="htt

导航条点击按钮切换效果

<!--[if IE]><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><![endif]--><html xmlns="http://www.w3.org/1999/xhtml"><head>&

JQuery移动动画实现点击按钮切换图片--JQuery基础

直接贴源码了哈,这些都是自己总结的……汗水几何?希望能帮到大家. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">

c# winform 点击按钮切换tabcontrol标签

this.tabControl1.TabPages.Remove(tabPage1); this.tabControl1.TabPages.Remove(tabPage2); this.tabControl1.TabPages.Add(tabPage2); TabPage tp = tabControl1.TabPages[0];//在这里先保存,以便以后还要显示 tabControl1.TabPages.Remove(tp);//隐藏(删除) tabControl1.TabPages.Inse

Android点击按钮切换背景效果-selector使用方法

有时候我们要实现“按下按钮和释放按钮时,按钮的背景图片(颜色)不同”的效果,我们可以用selector实现 1.编写XML代码:在项目的res/drawable目录下新建xml文件,添加相关代码: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <i

点击按钮切换内容效果(使用CSS DIV与JavaScript)

<head><script type="text/javascript">function change_div(id){  if (id == 'gsywly' )  {     document.getElementById("gsgs").style.display = 'none' ;     document.getElementById("gsywly").style.display = 'block' ;  

javascript学习代码--点击按钮显示内容

<!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-

JS实现PC、Android、IOS端的点击按钮复制内容功能

直接上代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>target-div</title> <meta name="viewport" content="width=device-width, initial-scale=1"> </hea

vue实现点击按钮,内容部分显示隐藏

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" con

前端点击按钮复制内容

一.VUE 效果: 代码: 1 <template> 2 <div> 3 <el-row style="height:40px" type="flex"> 4 <el-col :span="6"> 5 <p>{{res}}</p></el-col> 6 <el-col :span="2"> 7 <el-button type=