首页 > Web开发 > 详细

jQuery部分功能使用js进行实现(初探JQ)

时间:2019-01-16 17:58:05      阅读:168      评论:0      收藏:0      [点我收藏+]

今天使用js写了段jq中的html()方法。我的原则是废话不多说,直接放代码。。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JQuery初探</title>
</head>
<body>
    <div id="box">
        <span>1112</span>
    </div>
    <script>
        var Kodo = function(selector){
            return new Kodo.prototype.init(selector);
        }
        Kodo.prototype = {
            constructor : Kodo,
            length : 0,
            splice : [].splice,
            selector : ‘‘,
            id:{},
            init : function(selector){
                //这里统一认为是id
                if(selector){               
                     this.id = this.createrEleById(selector.substring(1,selector.length));
                }

            },
            html : function(){
                return this.toTrim(this.id.innerHTML);
            },
            createrEleById : function(idName){
                return document.getElementById(idName);
            },
            toTrim : function(str){
                //去除字符串两端空格
                return str.replace(/(^\s*)|(\s*$)/g, ""); 
            }
        }
        Kodo.prototype.init.prototype = Kodo.prototype;
        Kodo.prototype.ajax = function(){
            console.log(‘这里可以写ajax‘);
        }
        window.$ = Kodo;
        //$(‘#box‘).ajax();
        console.log($(‘#box‘).html());
    </script>
</body>
</html>

 

jQuery部分功能使用js进行实现(初探JQ)

原文:https://www.cnblogs.com/xiaohualu/p/10278139.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!