zepto - toggleClass

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>zepto</title>
    <style>
        .main {
            font-size: 120%;
            color: red;
        }
    </style>
</head>
<body>
<h1 id="h1">This is a heading</h1>

<p>This is a paragraph.</p>

<p>This is another paragraph.</p>
<button class="btn1">切换段落的 "main" 类</button>
<script src="zepto.min.js"></script>
<script>
    $("button").click(function () {
        $("p").toggleClass("main");
    });
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>zepto</title>
    <style>
        .listitem_1, .listitem_3 {
            color: red;
        }

        .listitem_0, .listitem_2 {
            color: blue;
        }
    </style>
</head>
<body>
<h1 id="h1">This is a heading</h1>
<ul>
    <li>Apple</li>
    <li>IBM</li>
    <li>Microsoft</li>
    <li>Google</li>
</ul>
<button class="btn1">添加或移除列表项的类</button>
<script src="zepto.min.js"></script>
<script>
    $("button").click(function () {
        $(‘ul li‘).toggleClass(function () {
            return ‘listitem_‘ + $(this).index();
        });
    });
</script>
</body>
</html>
时间: 2024-08-25 05:02:30

zepto - toggleClass的相关文章

读Zepto源码之样式操作

这篇依然是跟 dom 相关的方法,侧重点是操作样式的方法. 读Zepto源码系列文章已经放到了github上,欢迎star: reading-zepto 源码版本 本文阅读的源码为 zepto1.2.0 内部方法 classRE classCache = {} function classRE(name) { return name in classCache ? classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name

Zepto中文API

原文地址:http://zeptojs.com/ 译文地址:http://www.html-5.cn/Manual/Zepto/ Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jquery有着类似的api. 如果你会用jquery,那么你也会用zepto. 设计的目的是提供jquery的类似的APIs,但并不是100%覆盖jquery为目的.zepto设计的目的是有一个5-10k的通用库.下载并执行快.有一个熟悉通用的API,所以你能把你主要的精力放到应用开发上. Z

zepto.js 源码注释

/* Zepto v1.0-1-ga3cab6c - polyfill zepto detect event ajax form fx - zeptojs.com/license */ ;(function(undefined) { if (String.prototype.trim === undefined) // fix for iOS 3.2 String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''

zepto源码

/** * * ┏┓ ┏┓ * ┏┛┻━━━┛┻┓ * ┃ ┃ * ┃ ━ ┃ * ┃ ┳┛ ┗┳ ┃ * ┃ ┃ * ┃ ┻ ┃ * ┃ ┃ * ┗━┓ ┏━┛Code is far away from bug with the animal protecting * ┃ ┃ 神兽保佑,代码无bug * ┃ ┃ * ┃ ┗━━━┓ * ┃ ┣┓ * ┃ ┏┛ * ┗┓┓┏━┳┓┏┛ * ┃┫┫ ┃┫┫ * ┗┻┛ ┗┻┛ * */ /* Zepto 1.1.4 - zepto event aj

移动端的silder,未封装,基于zepto的touch模块,有参照修改过touch的bug

<!--html模块--> <header class="appoin-head"> <ul> <li class="aa"> <a href="#"> <img src="img/banner1.png" alt=""> </a> </li> <li> <a href="#"

原生JavaScript实现hasClass、addClass、removeClass、toggleClass

兼容IE6+,因IE6.IE7.IE8不支持Array.prototype.indexOf()和String.prototype.trim(),分别用Polyfill实现支持.详细:indexOf https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOftrim: https://developer.mozilla.org/en-US/docs/Web/JavaSc

Zepto.js详解【好大一篇文章】

参考:Zepto.js API 中文版(1.1.6) 下载 浏览器支持 模块 Change Log Acknowledgements Core $() $.camelCase $.contains $.each $.extend $.fn $.grep $.inArray $.isArray $.isFunction $.isPlainObject $.isWindow $.map $.parseJSON $.trim $.type add addClass after append appen

zepto的源代码注释(转)

/* Zepto v1.0-1-ga3cab6c - polyfill zepto detect event ajax form fx - zeptojs.com/license */ ;(function(undefined) { if (String.prototype.trim === undefined) // fix for iOS 3.2 String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''

[原创]zepto打造一款移动端划屏插件

最近忙着将项目内的jquery 2换成zepto 因为不想引用过多的zepto包,所以花了点时间 zepto真的精简了许多,源代码看着真舒服 正好项目内需要一个划屏插件,就用zepto写了一个 逻辑其实很简单,但没想到测试时,在老版本android设备浏览器上的touchmove有许多bug 做兼容倒是搞了一阵 效果图 样式1 样式2 调用 正常情况下应该是后台生成的html代码,但还是写了一套操作tab页的方法 调用简便如下: <link rel="stylesheet" hr