zoukankan      html  css  js  c++  java
  • JQuery插件

    1.页面

    @{
        ViewBag.Title = "Index";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    
    <ul id="ul">
        <li>第一行</li>
        <li>第二行</li>
        <li>第三行</li>
        <li>第四行</li>
        <li>第五行</li>
        <li>第六行</li>
    </ul>
    
    
    <ul id="ul2">
        <li>第一行</li>
        <li>第二行</li>
        <li>第三行</li>
        <li>第四行</li>
        <li>第五行</li>
        <li>第六行</li>
    </ul>
    <script>
        $(function ()
        {
            $.hello("CallmeYhz");
            $.log("你进入了页面");
    
    
            $("#ul li").click(function ()
            {
                $(this).Color();
            })
    
            $("#ul2 li").click(function () {
                $(this).Color2({
                    color: "blue",
                    append:"自定义插入内容成功"
                });
            })
    
        })
    </script>
    
    <!--引用自己的插件库><!-->
    <script src="~/Scripts/jquery_plug_custom.js"></script>

    2.脚本

    ;
    (function ($) {
        
        $.extend({
            //问好
            hello: function (name) {
                alert("你好啊!---" + name);
            },
            //测试日志打印
            log: function (message) {
                var now = new Date(),
                    y = now.getFullYear(),
                    m = now.getMonth() + 1, //!JavaScript中月分是从0开始的
                    d = now.getDate(),
                    h = now.getHours(),
                    min = now.getMinutes(),
                    s = now.getSeconds(),
                    time = y + '/' + m + '/' + d + ' ' + h + ':' + min + ':' + s;
                console.log(time + ' My App: ' + message);
            }
        });
    
    
        //拓展jquery对象的方法(无参数)
        $.fn.Color = function ()
        {
            this.each(function (index, ele) {
                $(this)
                    .css("color", "red")
                    .append("我居然被点击了")
                
            });      
        }
    
        //拓展jquery对象的方法(有参数)
        $.fn.Color2 = function (options) {
            var defaultStyle={
                color: "red",
                append: "我居然被点击了"
            }
            var setting = $.extend({}, defaultStyle, options);
    
           
            this.each(function (index, ele) {
                $(ele).css("color", setting.color);
                $(ele).append(setting.append);
            });
        };   
       
    })(jQuery);
  • 相关阅读:
    B. Ilya and Queries(前缀和)
    A. Cards for Friends(数学题)
    C. Given Length and Sum of Digits...(思维题)
    A. XORwice(水题)
    A. Raising Bacteria(位运算)
    最(cai)近(ji)总(shuo)结(hua)
    A. Road To Zero(水题)
    只要暴风骤雨才能使人迅速地成长
    Android Bitmap和Canvas学习笔记
    一些坑
  • 原文地址:https://www.cnblogs.com/CallmeYhz/p/6559859.html
Copyright © 2011-2022 走看看