html开始就执⾏某函数,⽴即执⾏函数.html ⽴即执⾏函数,可做框架
(function(w,d){
var readyRE=/loaded|complete|interactive/;//检测⽹页是否加载完成的与正则表达式
// var $=function(obj){
// return lector(obj);
// }
//检测选择器是ID,还是CLASS,还是TAG
//还可以在参数中再加⼀个参数⽤来指定要选取那个DOM下的⼦DOM
var $=function lector(obj,parent){
if(parent){
d=$(parent);
}
obj=obj.split(" ");
if(obj.length===1){
obj=obj[0];
}
var idSelector=/#\w+/i;
var claSelector=/\.\w+/i;
var tagSelector=/\w+/i;
var dom;
st(obj)){
//alert("id:"+obj)
place("#","");
dom = d.getElementById(obj);
}el st(obj)){
//alert("class:"+obj)
职责分离
place(".","");
dom = d.getElementsByClassName(obj);
}el st(obj)){
//alert('tag:'+obj)9年级化学
place("#","");
dom = d.getElementsByTagName(obj);
}
if(!dom.length){
dom.css=function(sty,t){
css(this,sty,t)
};
dom.html=function(string){
html(this,string);
}
dom.click=function(callback){
click(this,callback)
}
}el{
for(var i=0; i
dom[i].css=function(sty,t){
css(this,sty,t);
}stand
dom[i].html=function(string){
html(this,string);
}
dom[i].click=function(){
click(this)
}
}
}
return dom;
}
//表⽰⽹页已加载完成
//callback:function|⽹页加载完成的回调函数,相当于load $.ready = function ready(callback) {
if (adyState)) {
//$.write('leoxie')//这⾥可以添加UI代码
callback($);
} el {
步行英语document.addEventListener('DOMContentLoaded', function() {
//$.write('leoxie')//这⾥可以添加UI代码
callback($);
}, fal);
}
return this;
};
//===========事件=============
function click(obj,callback){
obj.οnclick=function(){callback()}
}
//===========样式======================
//获取或设置style的值
/
/dom:obj|⽤$(obj)获取到的元素
//sty:string|要设置或获取的属性
//t:stirng|要设置的值(选填)
function css(dom,sty,t){
//获取当前元素样式
var yangshi;
if(dom.currentStyle){
yangshi=dom.currentStyle;神奇的动物世界
//alert(box.currentStyle);
}el{
yangshi=getComputedStyle(dom,fal);
}
//判断函数参数个数来决定使⽤⽅法
狗屎糖
if(!t){
return yangshi[sty];
}el{
dom.style[sty]=t;福建大专排名
}
}
//===================元素内容=================== //获取元素的innerHMTL
//obj:obj|⽤$(obj)获取到的元素
//string:string|要设置的内容(选填)
function html(obj,string){
if(string){
obj.innerHTML=string;
京都第一瀑}el{
//有⼀个问题,不能返回内容,稍后再DEBUG return obj.innerHTML;
}
}
//============库详细============== $.version="1.0";
$.author="谢濛";
w.$=$;
})(window,document)
.
ll{
border:1px solid gray;
}
leo
ldo
adslkf
xie
meng
yes
⼀键复制
编辑
Web IDE
原始数据
按⾏查看
历史