/*
*YYJ.js mainly provides background application methods
*Currently there are Ajax, addLoadEvent, deleteAll, getByClass, $C(=getByClass), $, yyjtable, setCss, getCss, iaArray and other methods.Finally, a
*instantiable method YYJ.tick is provided to calculate the script running time
*version 0.1 --tianyi yyj
*/
var YYJ=function(){
var UniqueInstance;
function constrotor(){
return {
var isget=method .tolowercase () == "get";
var xmlhttp = window.xmlhttpRequest? New xmlhttprequest (): New Activexobject ("Microsoft.xmlhttp");
xml http.open (Method, URL, TRUE);
if(!isget)xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); If(xmlhttp.readyState= =4){
if(xmlhttp.status==200){
if(success)success(xmlhttp);
}
addLoadEvent:function(func) { onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
) {
oldonload();
}
func();
}
}
},//addLoadEvent
deleteAll:function(checkallbtn,checksomebtn,submitbtn){
var checkall=YYJ.$(checkallbtn);
var checksome=YYJ.$(checksomebtn);
var submit1=YYJ.$(submitbtn);
var checkboxs=(function(){
var arr=[];
var check=document.getElementsByTagName("input");
for(i=0;i if(check[i].getAttribute("type")!="checkbox")
continue;
arr.push(check[i]);
}
return arr;
})();
checkall.onclick=function(){
checkall.clicked=true;
for(var i=0;i if(!checkboxs[i].checked){
checkall.clicked=false;
break;
}
}
if(!checkall.clicked){
for(var i=0;i checkboxs[i].checked=true;
}
}else{
for(var i=0;i checkboxs[i].checked=false;
}
}
}
checksome.onclick=function(){
for(var x in checkboxs){
checkboxs[x].checked=!checkboxs[x].checked;
}
}
submit1.onclick=function(){
var haschecked=false;
var beSureDel=false;
for(var i=0;i if(checkboxs[i].checked){
haschecked=true;
break;
}
}
haschecked?function(){
beSureDel=confirm("确定要删除选中项吗?");
}():function(){
alert("没有选中项!");
beSureDel=false;
}();
return beSureDel;
}
},//deleteall
getByClass:function(classname,parent,nodename){
var s=(parent||document).getElementsByTagName(nodename||"*");
return function(){
var a=[];
for(var i=0,j=s.length;i if(!s[i].className) continue;
var name=" " s[i].className " ";
if(name.indexOf(" " classname " ")!=-1){
a.push(s[i]);
}
}
return a;
}();
},
$C:function(classname,parent,nodename){
return YYJ.getByClass(classname,parent,nodename);
},//getByClass
$:function(str){
return document.getElementById(str);
},//getById
yyjtable:function(tableId){
var tbl=YYJ.$(tableId);
var trs=tbl.getElementsByTagName("tr");
for(var i=1;i if(i%2!=0){
trs[i].style.backgroundColor="#FFFFF0";
}else{
trs[i].style.backgroundColor="white";
}
trs[i].onmouseover=function(){
this.col1=this.style.backgroundColor;
this.style.backgroundColor="#FFFACD";
}
trs[i].onmouseout=function(){
this.style.backgroundColor=this.col1;
}
}
},//yyjtable
/*使用方法
YYJ.setCss([YYJ.$("table1")],{
color:"red",
backgroundColor:"silver"
});*/
setCss:function(eles,opt){
if(!eles||!opt)return;
if(!eles.length){
throw new Error("setCss的第一个参数要求为数组!");
}
for(var i=0;j=eles[i];i ){
try{
for(var x in opt){
j.style[x]=opt[x];
}
}catch(ex){}
}
},//setCss
/*使用方法
var css=YYJ.getCss(YYJ.$("table1"),["backgroundColor"]);
alert(css["backgroundColor"]);*/
getCss:function(ele,opt){
if(!this.isArray(opt)){
throw new Error("getCss的第二个参数要求为string数组!");
}
var css={};
for(var i=0,j=opt.length;i try{
css[opt[i]]=ele.style[opt[i]];
}catch(ex){}
}
return css;
},//getCss
isArray:function(opt){
return Object.prototype.toString.call(opt)=="[object Array]"
}
};
}
function getUniqueInstance(){
if(UniqueInstance){
return UniqueInstance;
}
UniqueInstance=constrotor();
return UniqueInstance;
}
return getUniqueInstance();
}();
//脚本执行时间
/*使用方法
var ti=new YYJ.ticks();
ti.begin();
代码段
ti.end();
alert(ti.tick);*/
YYJ.ticks=function(){
var starttick,stoptick;
return function(){
this.begin=function(){
starttick=new Date();
}
this.end=function(){
stoptick=new Date();
this.tick=stoptick-starttick;
}
}
}();
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn