当前位置:编程学习 > JS >>

脚本吧 - 幻宇工作室用到js,超强推荐base.js

答案:base.js
复制代码 代码如下:

browser_init()
function browser_init(){
window.isIE=navigator.appName.indexOf("Microsoft")==0
window.$sys={}
window.$my={}
String.prototype.trim=function(){return this.replace(/(^[\s]*)|([\s]*$)/g,"")}
String.prototype.inc=function(s1,s2){if(s2==null){s2=","};return (s2+this+s2).indexOf(s2+s1+s2)>-1?1:0}
String.prototype.lenB=function(){return this.replace(/[^\x00-\xff]/g,"**").length}
String.prototype.leftB=function(len,isOmit){var s;s=this.replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**");if(s.length>len&&isOmit){len-=3};return this.slice(0,s.slice(0,len).replace(/\*\*/g," ").replace(/\*/g,"").length)+(s.length>len&&isOmit?"...":"")}
String.prototype.getVar=function(str,def){if(this.inc(str,";"))return 1;var a=this.match(new RegExp("(^|;)"+str+":[^;]*"));return a==null||str==""?(def==null?"":def):a[0].replace(";","").slice(str.length+1)}
String.prototype._slice="".slice
String.prototype.slice=function(n1,n2){var v,b1=typeof(n1)=="number",b2=typeof(n2)=="number";if(!b1||typeof(n2)=="string"){v=eval("this._slice("+(b1?n1:this.indexOf(n1)+(n2==null?1:0)+(this.indexOf(n1)==-1?this.length:0))+(n2==null?"":(b2?n2:(this.indexOf(n2)==-1?"":","+this.indexOf(n2))))+")")}else{v=eval("this._slice(n1"+(n2==null?"":","+n2)+")")}return v}
Array.prototype.parseInt=function(){var i,count=this.length;for(i=0;i<count;i++){this[i]=parseInt(this[i])}}
Array.prototype.remove=function(item){var i,count=this.length;for(i=0;i<count;i++){if(this[i]==item){this.splice(i,1);i--;count--}}}
Array.prototype.plus=function(item){for(var i=0;i<this.length;i++){if(this[i]==item){return}}this.push(item)}
window.$=function(obj){return typeof(obj)=="string"?document.getElementById(obj):obj}
window.ow=function(win){return $(win).contentWindow}
window.oDel=function(obj){if($(obj)!=null){$(obj).parentNode.removeChild($(obj))}}
window.oHide=function(obj){if($(obj)!=null){$(obj).style.visibility="hidden"}}
window.oShow=function(obj){if($(obj)!=null){$(obj).style.visibility=""}}
window.oFocu=function(obj){window.tempObj=$(obj);window.setTimeout("try{window.tempObj.focus()}catch(e){}",10)}
window.fmCheck=function(){return true}

$sys.url=location.href
$sys.path=$sys.url.slice(0,"?").slice(0,$sys.url.lastIndexOf("/")+1)
document.write("<body></body>")
if(document.all){
document.execCommand("BackgroundImageCache",false,true)
}
else{
HTMLElement.prototype.attachEvent=function(type,foo){this.addEventListener(type.slice(2),foo,false)}
HTMLElement.prototype.contains=function(node){if(!node)return false;do if(node==this){return true}while(node=node.parentNode){return false}}
HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){var r=this.ownerDocument.createRange();r.setStartBefore(this);var df=r.createContextualFragment(sHTML);this.parentNode.replaceChild(df,this);return sHTML;})
HTMLElement.prototype.__defineGetter__("innerText",function(){var r = this.ownerDocument.createRange();r.selectNodeContents(this);return r.toString()})
Event.prototype.__defineGetter__("srcElement",function(){var node=this.target;while(node.nodeType!=1){node=node.parentNode}return node})
Event.prototype.__defineGetter__("fromElement",function(){return this.relatedTarget})
Event.prototype.__defineGetter__("toElement",function(){return this.relatedTarget})
Event.prototype.__defineGetter__("offsetX",function(){return this.layerX})
Event.prototype.__defineGetter__("offsetY",function(){return this.layerY})
}
drag_init()
thd_init()
document_onload()
}
function document_onload(){
var l
l="<div id=mcSystem style='position:absolute;left:-9000px;top:0'>"
l+="<iframe id=wForm name=wForm onload=fmWinOnLoad(this)></iframe>"
l+="<button id=btSysFocu></button>"
l+="</div>"
insHtm(document.body,l)
document.body.onmouseover=document.body.onmouseout=document.body.onmousedown=document.body.onmouseup=function(e){
var ee
e=e||event
ee=e.srcElement
if(e.type=="mouseover"&&(ee.tagName=="A"||ee.tagName=="INPUT"||ee.tagName=="LABEL")&&!ee.hideFocus)
ee.hideFocus=true
}
document.body.onkeydown=function(e){
var ee
e=e||event
ee=e.srcElement
if(ee.tagName=="INPUT"&&e.keyCode==13&&isIE&&ee.form!=null){
if(ee.form.btSubmit!=null)
ee.form.btSubmit.click()
}
}
if(window.body_onload!=null)
body_onload()
}
function drag_init(){
window.$drag={}
window.startDrag=function(obj,e){
$drag.obj=$(obj)
$drag.x0=$drag.obj.offsetLeft
$drag.y0=$drag.obj.offsetTop
$drag.sx=e.clientX
$drag.sy=e.clientY
if(document.all)
$drag.obj.setCapture()
}
document.onmouseup=function(){
if($drag.obj==null)
return
if(document.all)
$drag.obj.releaseCapture()
$drag.obj=null
}
document.onmousemove=function(e){
var x,y
if($drag.obj==null)
return
e=e||event
x=Math.min(e.clientX-$drag.sx+$drag.x0,document.body.scrollLeft+document.body.clientWidth-$drag.obj.offsetWidth)
y=Math.min(e.clientY-$drag.sy+$drag.y0,document.body.scrollTop+document.body.clientHeight-$drag.obj.offsetHeight)
x=Math.max(x,0)
y=Math.max(y,document.body.scrollTop)
$drag.obj.style.left=x+"px"
$drag.obj.style.top=y+"px"
}
}
function thd_init(){
window.$thd={}
$thd.items=[]
$thd.index=0
$thd.push=function(foo,interval){
foo.interval=interval==null?1:interval
$thd.items.push(foo)
}
$thd.remove=function(foo){
$thd.items.remove(foo)
}
$thd.run=function(){
var ol=$thd.items,i
for(i=0;i<ol.length;i++){
if($thd.index%ol[i].interval==0||ol[i].start==null){
ol[i].start=1
ol[i]()
}
}
$thd.index++
window.setTimeout("$thd.run()",10)
}
$thd.run()
}
function $x(obj,op){
var o,x=0
op=op||document.body
do{
o=o==null?$(obj):o.parentNode
if(op==o)
break
x+=o.offsetLeft
}while(op.contains(o))
return x
}
function $y(obj,op){
var o,y=0
op=op||document.body
do{
o=o==null?$(obj):o.parentNode
if(op==o)
break
if(o.tagName=="TR")
continue
y+=o.offsetTop-o.scrollTop
}while(op.contains(o))
return y
}
function getPngBg(url){
return document.all&&/\.png/i.test(url)?"filter:progid:dximagetransform.microsoft.alphaimageloader(src="+url+",sizingMethod=scale)":"background:url("+url+")"
}
function setHtm(op,str){
op=$(op)
if(op.tagName=="TABLE"){
if(op.tBodies.length==0)
op.appendChild(document.createElement("tbody"))
op.replaceChild(document.createElement("tbody"),op.tBodies[0])
}
else
op.innerHTML=""
insHtm(op,str)
}
function ins

上一个:js不是基础的基础
下一个:Javascript实例教程(19) 使用HoTMetal(1)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,