📄 public.js
字号:
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
function countLength(obj){
if(obj==null)return;
var dLen = 0,sLen = 0;
for(i=0; i< obj.length; i++ ){
if(obj.charCodeAt(i) > "0" && obj.charCodeAt(i) < "128")
sLen+=1;
else
dLen+=2;
}
totalLen = sLen+dLen;
return totalLen;
}
//cody by jarry;
String.prototype.trim = function()
{ return this.replace(/(^\s*)|(\s*$)/g, "");}
function isExist(child,obj){
//obj has element the child;
for(var i=0;i<obj.elements.length;i++){
if(obj.elements[i].tagName.toLowerCase()=="input" && obj.elements[i].type=="checkbox"){
if(obj.elements[i].value==child)return true;
}
}
return false;
}
function validateURL(url){
//validateURL
//if(url.search(/^[A-Za-z0-9 -]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/)!=0){
if(url.indexOf(".") < 0){
//放宽限域名制含
return false;
//}else if(url.substring(0,4)=="www."){
//网址不要前面的www.,如果没用的话可以注释掉;
//return false;
}else{
return true;
}
}
function showTip(msg){
var t=$("tip");
t.innerHTML=msg;
t.className="tip";
}
//clear tips;
var tm=0;var start;
function closeTip(){
tm++;
start = setTimeout(closeTip,200);
if(tm >= 5){
clearTimeout(start);
showTip(" ");tm = 0;
$("tip").className="";
}
}
//return true or false when press ctrl key on the update input
function onCtrlDown(evt){
var kc = evt.keyCode;
alert(kc);
/*
var isCtrlkey = false;
if(kc==13){
//if press is Ctrl key and the input is not empty
isCtrlkey = true;
}
return isCtrlkey;*/
}
//设定按钮的状态
function setStatus(obj,thisform){
//多选按钮
var f = thisform; var list = obj;
var hasDivChild = false;
if(list.childNodes.length>0 ){
for(var i=0;i<list.childNodes.length;i++){
var s=list.childNodes[i];
if( typeof(s)!="undefined" && s.tagName) {
if(s.tagName.toUpperCase()=="DIV")
hasDivChild = true;
}
}
}
f.check.disabled = hasDivChild ?false:true;
f.check.value=strAll;
//反选
f.recheck.disabled = hasDivChild ?false:true;
//删除
f.remove.disabled = hasDivChild ?false:true;
if( !hasDivChild ){
showTip("没有数据");
}
}
var emptyCol="",overCol="#f1f1f1",checkedCol="#F4FFF4";
function getAbsoluteLeft( ob ){
if(!ob){return null;}
var obj = ob;
var objLeft = obj .offsetLeft;
while( obj != null && obj .offsetParent != null && obj .offsetParent.tagName != "BODY" ){
objLeft += obj .offsetParent.offsetLeft;
obj = obj .offsetParent;
}
return objLeft ;
}
// get absolute TOP position
function getAbsoluteTop( ob ){
if(!ob){return null;}
var obj = ob;
var objTop = obj .offsetTop;
while( obj != null && obj .offsetParent != null && obj .offsetParent.tagName != "BODY" ){
objTop += obj .offsetParent.offsetTop;
obj = obj .offsetParent;
}
return objTop ;
}
function disableButton(_is , thisform){
var f = thisform;
f.check.disabled = _is;
f.recheck.disabled = _is;
f.remove.disabled = _is;
}
var currentDiv;
var currentDiv;
function showDelete(self){
self.style.backgroundColor = overCol;
currentDiv = self;
var theid = "del_icon";
if(!$(theid)){
var delDiv=document.createElement("div");
delDiv.id=theid;
var d=delDiv;
d.style.textAlign="center";d.style.fontSize="11px";
var edit = document.createElement("span");
edit.title="编辑此条";edit.style.textDecoration="underline";
edit.onclick=function(){
editSingle(currentDiv.parentNode,this.parentNode,currentDiv);
}
var del = document.createElement("span");
del.title="删除此条";del.style.textDecoration="underline";
del.onclick=function(){
delSingle(currentDiv.parentNode,this.parentNode,currentDiv);
}
edit.appendChild(document.createTextNode("edit"));
d.appendChild(edit);
d.appendChild(document.createTextNode(" | "));
del.appendChild(document.createTextNode("delete"));
d.appendChild(del);
d.style.width="80px";
d.style.lineHeight="20px";
d.style.color="blue";
// d.style.zIndex="-10";
// d.style.backgroundColor="green";
document.body.appendChild(d);
$(theid).onmouseover=function(){
currentDiv.style.backgroundColor = overCol;
this.style.display="";
//mouseOndeleteDiv=true;
}
/* $(theid).onclick=function(){
delSingle(currentDiv.parentNode,this,currentDiv);
}*/
//
$(theid).style.cursor="pointer";
}
if($(theid)){
$(theid).style.display="";
var l= getAbsoluteLeft(self) + self.offsetWidth - 80;
var t= getAbsoluteTop(self) + 5;
var scrollT = self.parentNode.scrollTop;//减去出现滚动条的高度;
var t= getAbsoluteTop(self) + 5 - scrollT;
//document.title = getAbsoluteLeft(self) +"|"+ getAbsoluteTop(self) +"|"+ self.offsetWidth +"|"+ self.offsetHeight + "t:"+t + "l:"+l;
$(theid).style.position="absolute";
$(theid).style.left = l+"px";
$(theid).style.top = t+"px";
}
}
function hideDelete(self){
var theid = "del_icon";
if( $(theid) ){
self.style.backgroundColor = self.childNodes[0].checked?checkedCol:emptyCol;
$(theid).style.display="none";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -