javascript 创建并导入自定义库,前端研发岗面试复盘总结

//修改属性

/*

两个参数:修改属性

一个参数:获取属性

一个参数:批量设置属性

*/

Base.prototype.attr=function(property,value){

if(value!=undefined){

for(var i=0;i<this.ele.length;i++){

this.ele[i][property]=value;

}

}else if(typeof property==‘object’){

//批量设置

for(var j=0;j<this.ele.length;j++){

for(var m in property){

this.ele[j][m]=property[m];

}

}

}else{

//获取属性值

return this.ele[0][property];

}

return this;

};

//修改内容

/*

1.有参数:修改内容

2.无参:获取指定节点的内容

*/

Base.prototype.text=function(value){

//arguments

//有参数

if(value!=undefined){

//遍历节点

for(var i=0;i<this.ele.length;i++){

this.ele[i].innerHTML=value;

}

return this;

}

return this.ele[0].innerHTML;//返回第一个节点的内容

};

//事件

Base.prototype.click=function(fn){

for(var i=0;i<this.ele.length;i++){

this.ele[i].οnclick=fn;

}

};

//hover事件

Base.prototype.hover=function(fn_over,fn_out){

for(var i=0;i<this.ele.length;i++){

this.ele[i].οnmοuseοver=fn_over;

this.ele[i].οnmοuseοut=fn_out;

}

return this;

};

//效果类型

//显示

Base.prototype.show=function(){

for(var i=0;i<this.ele.length;i++){

this.ele[i].style.display=‘block’;

}

return this;

};

//隐藏

Base.prototype.hide=function(){

for(var i=0;i<this.ele.length;i++){

this.ele[i].style.display=‘none’;

}

return this;

};

//切换

Base.prototype.toggle=function(){

for(var i=0;i<this.ele.length;i++){

var o=this.ele[i];

//获取节点状态

var sty=o.style.display;

if(sty==‘’){

sty=window.getComputedStyle(o,null).display;

}

if(sty==‘none’){

o.style.display=‘block’;

}else{

o.style.display=‘none’;

}

}

return this;

};

//在创建一个html

Document
嘎哈
拉开距离科技
坎坎坷坷扩
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值