>  기사  >  웹 프론트엔드  >  Jquery 연결 Syntax_jquery를 구현하는 방법

Jquery 연결 Syntax_jquery를 구현하는 방법

WBOY
WBOY원래의
2016-05-16 17:47:411094검색

JavaScript에 익숙한 사람이라면 누구나 jquery에 대해 알고 있을 것입니다. Jquery의 기능 중 많은 부분이 매우 흥미롭습니다. 그 중 하나는 고유한 연결 쓰기 구문입니다. 그럼 이를 어떻게 구현해 볼까요? .

코드 복사 코드는 다음과 같습니다.

sx.$=function (id) {
var t=(typeof(id)=="string"?document.getElementById(id):id);
t.text=function(){
this.innerText를 반환합니까? :this.innerHTML.replace(//<.>}
t.html=function(){
return this.innerHTML? :null
}
t.first=function(){
return this.firstChild?this.firstChild.nodeName!="#text"?sx.$(this.firstChild): null:null ;
}
t.last=function(){
return this.lastChild?this.lastChild.nodeName!="#text"?sx.$(this.lasChild):null: null
}
t.pre=function(){
return this.previousSibling?sx.$(this.previousSibling):null
}
t.next=function() {
return this.nextSibling?sx.$(this.nextSibling):null;
}
t.parent=function(){
return this.parentNode?sx.$(this.parentNode ):null ;
}
t.setevent=function(e,f){
if(t.attachEvent){
t.attachEvent("on" e,f)
}else{
t.addEventListener(e,f,false);
}
}
t.removeevent=function(e,f){
if(t.dettachEvent){
t .dettachEvent("on" e,f);
}else{
t.removeEventListener(e,f,false)
}
}
t.setstyle=함수(들) {
var s=s.split(",");
for(var i=0;ivar s1=s[i].split (": ");
this.style[s1[0]]=s1[1];
}
}
t.getstyle=function(s){
if(this .currentStyle) {
return this.currentStyle[s];
}else{
return document.defaultView.getCompulatedStyle(this,null).getPropertyValue(s)
}
}
t .selectpath=function(m){
var m1=m;
var m=m.split("/")
var t=[]
var e=this .getElementsByTagName( "*");
for(var i=0;ivar e1=e[i]
var a=""
var i1=m .length-1;
while(e1!=this){
a=e1.tagName "/" a
e1=e1.parentNode
//alert(a)
}
//alert(a);
if(m1.toLowerCase() "/"==a.toLowerCase()){
t.push(sx.$(e[ i]) );
}
}
return t;
}
t.get=function(a){
return this.getAttribute(a); t.set=function(a,v){
return this.setAttribute(a,v)
}
t.paste=function(h){
if(typeof(h)= ="string"){
var d=document.createElement("span");
d.innerHTML=h;
}else{
var d=document.createElement("span") ;
d.appendChild(h);
}
var t1=this.childNodes
for(var i=0;i 경고(t1 [i])
this.removeChild(t1[i]);
}
this.appendChild(d);
d.removeNode(false)
}
return t ;
}
sx.$$=function(){
var t=[]
for(var i=0;i t.push (sx.$(arguments[i]))
}
return t;
}


위 코드는 제가 최근에 크로스 플랫폼 자바스크립트 프레임워크 A를 위해 작성한 코드입니다. 핵심 코드를 보면 재귀를 사용하여 연결 구문을 구현하고 자체 메서드에서 계속 자신을 호출하여 클로저를 실험하고 개체의 지속적인 작업을 활성화하는 것을 볼 수 있습니다. 여기에 객체가 속성이면 innerHTML에 표시됩니다.

시험이 곧 다가오고 전공이 컴퓨터와는 관련이 없지만 공부할 시간이 많지 않습니다. , 그래도 수업에 낙제하지 않기를 바랍니다.
기사에 부족한 점이 있으면 지적해 주시기 바랍니다.
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.