js步骤(1)

js方法(1)

(function () {
 var reg = /^[A-Za-z]+$/;
 var isHtml = /<|&#?\w+;/;
 String.prototype.startWith = function () {
  return this.charAt(0);
 };
 String.prototype.content = function () {
  return this.substring(1, this.length);
 };
 this.$ = jQuery = function (selected) {
  return new jQuery.fn.init(selected);
 };
 jQuery.fn = jQuery.prototype = {init:function (selected, context) {
  selected = this.trim(selected);
  if (selected.nodeType) {
   this.length = 1;
   return this;
  }
  if (typeof selected === "string") {
   if (selected.startWith() === "#") {
    this.length = 1;
    this[0] = document.getElementById(selected.content());
    this.selected = selected;
    return this;
   }
   if (selected.startWith() === ".") {
    var l = this.getTagName("*").length;
    var e = this.getTagName("*");
    var es = [];
    for (var i = 0; i < l; i++) {
     if (e[i].className == selected.content()) {
      es.push(e[i]);
     }
    }
    for (var j = 0; j < l; j++) {
     this[j] = es[j];
    }
    this.length = es.length;
    return this;