jquery组件和插件写法

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="智能社 - zhinengshe.com" />
<meta name="copyright" content="智能社 - zhinengshe.com" />
<title>智能社 - www.zhinengshe.com</title>
<style>
#div1{width:200px; height:200px; background:#ccc;}
</style>
<script src="jquery-1.7.2.js"></script>
<script>

$.fn.toRed = function(){
    //插件里面的this 是jquery对象
    this.css("background","red");
};

$.fn.toGreen = function(){
    //插件里面的this 是jquery对象
    this.css("background","green");
};

$(function(){
    $("#div1").toggle(function(){
        $(this).toRed();
    },function(){
        $(this).toGreen();
    });
});
</script>
</head>

<body>

<div id="div1"></div>

</body>
</html>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="智能社 - zhinengshe.com" />
<meta name="copyright" content="智能社 - zhinengshe.com" />
<title>智能社 - www.zhinengshe.com</title>
<style>
#div1{width:200px; height:200px; background:#ccc;}
</style>
<script src="jquery-1.7.2.js"></script>
<script>

$.fn.extend({
    toRed:function(){
        this.css("background","red");
    },
    toGreen:function(){
        this.css("background","green");
    }
});

$(function(){
    $("#div1").toggle(function(){
        $(this).toRed();
    },function(){
        $(this).toGreen();
    });
});
</script>
</head>

<body>

<div id="div1"></div>

</body>
</html>

<!--
智能社© - http://www.zhinengshe.com/

微博:@北京智能社
微信:zhi_neng_she

最具深度的前端开发培训机构 HTML+CSS/JS/HTML5
-->

<!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>淘宝幻灯片上下滑动效果 —— www.zhinengshe.com —— 智能社</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<script src="../jquery-1.7.2.js"></script>
<script src="slide.js"></script>
<script>
$(function(){
    $("#play").slide();
    $("#play2").slide();
});
</script>
</head>

<body>

<div class="play" id="play">
    <ol>
        <li class="active">1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ol>
    <ul>
        <li><a href="http://www.zhinengshe.com/"><img src="images/1.jpg" alt="广告一" /></a></li>
        <li><a href="http://www.zhinengshe.com/"><img src="images/2.jpg" alt="广告二" /></a></li>
        <li><a href="http://www.zhinengshe.com/"><img src="images/3.jpg" alt="广告三" /></a></li>
        <li><a href="http://www.zhinengshe.com/"><img src="images/4.jpg" alt="广告四" /></a></li>
        <li><a href="http://www.zhinengshe.com/"><img src="images/5.jpg" alt="广告五" /></a></li>
    </ul>
</div>

<div class="play" id="play2">
    <ol>
        <li class="active">1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ol>
    <ul>
        <li><a href="http://www.zhinengshe.com/"><img src="images/1.jpg" alt="广告一" /></a></li>
        <li><a href="http://www.zhinengshe.com/"><img src="images/2.jpg" alt="广告二" /></a></li>
        <li><a href="http://www.zhinengshe.com/"><img src="images/3.jpg" alt="广告三" /></a></li>
        <li><a href="http://www.zhinengshe.com/"><img src="images/4.jpg" alt="广告四" /></a></li>
        <li><a href="http://www.zhinengshe.com/"><img src="images/5.jpg" alt="广告五" /></a></li>
    </ul>
</div>
</body>
</html>

//版权 北京智能社©, 保留所有权利

$.fn.slide = function (){
    var $aBtn =this.find("ol li");
    var $oUl = this.find("ul");
    var $aLi = this.find("ul li");

    var iNow = 0;

    var timer = setInterval(next,1000);

    this.hover(function(){
        clearInterval(timer);
    },function(){
        timer = setInterval(next,1000);
    });

    function next(){
        iNow++;

        if(iNow == $aLi.length){
            iNow = 0;
        }
        tab();
    }

    $aBtn.mouseover(function(){

        iNow = $(this).index();
        tab();
    });

    function tab(){
        $aBtn.removeClass("active");
        $aBtn.eq(iNow).addClass("active");

        $oUl.stop().animate({top:-$aLi.height()*iNow});
    }
};

时间: 2024-08-04 11:07:24

jquery组件和插件写法的相关文章

jquery插件写法

下面的文章是我复制粘贴的,是学习jquery插件写法时搜到的好的教程.谢谢这些人写的博客,为表示尊重,我将博客的地址也粘贴出来,希望可以帮到其他人. -----------------------------------------------------分割线--------------------------------------------------------------------------------------------------- JQuery插件写法的总结 最近Web

jquery 扩展和插件的写法

1.jquery扩展的方法常用的就是$.fn.xxx, 这个我理解的其实扩展jquery 实例中的属性或者方法 (function ($) { $.fn.alertSelf = function () { $(this).on('click',function () { alert( $(this).html() ); }) } })(jQuery); 这个扩展jquery实例中的方法,使用方法$("#idxx").alertSelef() 给某个节点添加了一个绑定弹出自身内容的方法

jQuery组件写法

知识点: 什么是插件 jQuery插件的模式 jQuery插件的Lightweight Start模式(入门级插件模式) 8.1 插件(Plug-in) “插件”这个关键字,估计大家在日常生活中经常有所耳闻.例如:各网页浏览器,允许用户安装一些插件,增强用户体验,常见的Adobe Flash播放器,银行安全交易插件等.对于不做编程的朋友来说,是一个无所谓的词,但是对于咱们IT技术行业的朋友来说,是必须要了解,知道的. 咱们不是学者,不做特别规范的学术性研究,只要能够理解.够用就可以了. 因为咱们

jQuery插件写法总结以及面向对象方式写法总结

[转自]jQuery插件写法总结以及面向对象方式写法总结:http://www.xuanfengge.com/jquery-plug-in-written-summary-and-summary-of-writing-object-oriented-manner.html

jQuery插件写法总结

jQuery插件写法总结:http://www.xuanfengge.com/jquery-plug-in-written-summary-and-summary-of-writing-object-oriented-manner.html

第七章(插件的使用和写法)(7.2 jQuery 表单插件 ----- Form)

7.2 jQuery 表单插件 ----- Form 7.2.1 Form 插件简介 jQuery Form 插件是一个优秀的 Ajax 表单插件,可以非常容易地.无侵入地升级 HTML 表单以支持 Ajax.jQuery Form 有两个核心方法----- ajaxForm()  和 ajaxSubmit() .它们集合了从控制表单元素到决定如何管理提交进程的功能,另外,插件还包括其他一些方法: formToArray() / formSerialize() / fieldSerialize(

jQuery组件开发之表格隔行选中效果实现

一.效果展示如下 jQuery组件之表格插件源码 1 //表格选中插件 2 //方式一 3 (function($){ 4 var chosTabBgColor = function(options){ 5 //设置默认值 6 var options = $.extend({ 7 odd:"odd", //奇数 8 even:"even",//偶数 9 selected:"selected" 10 },options); 11 12 $(&quo

jquery数字打分插件与嵌入到EasyUI datagrid中的示例

这阵儿是断续折腾定性考评表打分的事儿了.虽是UI菜鸟,但却一直想让用户在操作上更加方便,之前基于"jQuery星级评分插件"实现了一个评分界面(因为比较简单,就不做总结了),用户反应还不错. 这一次的评分表中,各项分值的特点有:一是每个评分项的分值均不太一样:二是分值为整数,但分值范围大,从-1000到+1000都存在.若是采用在datagrid中嵌入编辑框的形式实现的话,总是觉得让用户使用不太方便,所以内心非常想做一个数字插件,然后就搜到中意的例子--"简单的jQuery用

四款超棒的jQuery数字化签名插件

在浏览器中,我们有很多方式来绘制生成签名效果,并且有很多很棒很智能的jQuery插件.数字化签名是未来的发展方向,正是这个原因我们这里收集并且推荐了四款超棒的jQuery数字化签名插件,希望大家喜欢! 1. jSignature 这个jQuery插件简化了创建数据签名的过程,允许用户使用鼠标,手写板,手指来绘制签名.这里是演示 2. Signature Pad 这个jQuery插件可以辅助使用HTML5画布来实现数字签名.它保存签名为JSON,并且可以以后再重新生成,这里是演示 3. jQuer