为了账号安全,请及时绑定邮箱和手机立即绑定

通用函数是怎么理解

var g = function (id){
   if(id.substr(0,1)=='.'){
       return document.getElementsByClassName(id.substr(1));
   }
   return document.getElementById(id);

}



正在回答

1 回答

var g = function (id){               //id为该函数传入的参数
   if(id.substr(0,1)=='.'){            //判断  substr(0,1)  截取传入的参数id 从0 开始截取1位 是否 和字符串'.'相同 
       return document.getElementsByClassName(id.substr(1));    // 条件成立 返回 document.getElementsByClassName(截取id从第1未开始到结尾的字符串)
   }
   return document.getElementById(id);   //条件不成立 返回document.getElementById(id); 

}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

通用函数是怎么理解

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号