⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comman.js

📁 mcu5toolbox 单片机工具集
💻 JS
字号:
String.prototype.lenB   =   function(){return   this.replace(/[^\x00-\xff]/g,"**").length;}
String.prototype.GetLimitString = function(bytelen,limitstr,limitlen)
{
	if(this.lenB()<= bytelen+limitlen)
		return this;
	var i=0,j=0;
	var newstr = "",tmp="";
	while(i<bytelen)
	{
		tmp = this.substr(j,1);
		if(tmp.lenB()>1)
		{
			i++;
		}
		newstr += tmp;
		i++;
		j++;
	}
	return newstr+limitstr;
}

String.Format = function() {
 
 if(arguments.length == 0)
  return "";
 
 if(arguments.length == 1)
  return arguments[0];
 
 var reg = /{(\d+)?}/g;
 var args = arguments;
 var result = arguments[0].replace(
  reg,
  function($0, $1) {
   return  args[parseInt($1)+1];
  }
 )

 return result;
}

//图片最大宽1
var varPicMaxWidth1 = 600;
//图片最大宽2
var varPicMaxWidth2 = 300;
// 图片缩放脚本
var flag=true; 
function DrawImage(ImgD){ 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0){ 
        flag=true; 
        if(image.width>=varPicMaxWidth1){ 
            ImgD.width=varPicMaxWidth1; 
            ImgD.height=(image.height*varPicMaxWidth1)/image.width; 
        }else{ 
            ImgD.width=image.width; 
            ImgD.height=image.height; 
        }  
    } 
} 
// 图片缩放脚本
var flag=true; 
function DownImage(ImgD){ 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0){ 
        flag=true; 
        if(image.width>=varPicMaxWidth2){ 
            ImgD.width=varPicMaxWidth2; 
            ImgD.height=(image.height*varPicMaxWidth2)/image.width; 
        }else{ 
            ImgD.width=image.width; 
            ImgD.height=image.height; 
        }  
    } 
} 
function cgimg(o){
var zoom=parseInt(o.style.zoom, 10)||100;
zoom+=event.wheelDelta/12;
if(o.width*zoom/100 > varPicMaxWidth1)
	return false;
if (zoom>0) o.style.zoom=zoom+'%';
return false;
}


function procSelectAll(isChecked)
{
  var i;
  i=1;
  while(true)
  {
     obj=eval('window.ctlForm1.chid'+i);
	 if(obj)
	  obj.checked=isChecked;
	 else
	   break;
	 i++;
  }
}

function procBindSelect(objArr,objSelect,SelectedId)
{
	var oOption;
    var i=0;

	objSelect.options.length = 0;
	oOption = document.createElement("OPTION");
		oOption.text='-请选择-';
		oOption.value='';
		objSelect.add(oOption);
	while(objArr[i])
	{
		oOption = document.createElement("OPTION");
		oOption.text=objArr[i][1];
		oOption.value=objArr[i][0];
		objSelect.add(oOption);
		i++;
	}
	if(SelectedId>0)
		objSelect.value=SelectedId;
}

function procBindName(objArr,selectedid)
{
	for(var i=0;i<objArr.length;i++)
	{
		if(objArr[i][0] == selectedid){
			document.write(objArr[i][1]);
			return;
		}
	}
	return "";
}

function procBindSelect2(objArr,Selected)
{
	var oOption = '<option value="" >返回</option>';

	for(var i=0;i<objArr.length;i++)
	{
		if(objArr[i] != ''){
		if(objArr[i] == Selected)
		{
			oOption += '<option value="'+objArr[i]+'" selected>'+objArr[i]+'</option>';
		}
		else
		{
			oOption += '<option value="'+objArr[i]+'" >'+objArr[i]+'</option>';
		}
		}
	}
	document.write(oOption);
}

//history.go(-1)
function GoBack(url)
{
var lasturl = document.referrer;
if(lasturl != null && lasturl != "")
{
	history.go(-1);
}
else
{
	if(url != null && url != "")
		window.location.href=url;
}
}

//language
function ChangeLanguage(langurl)
{
	if(langurl != null && langurl != "")
		window.location.href = langurl;
}
function DoSearchByType()
{
	var search = $('header_search_text').value;
	if(search)
		search = search.replace(" ","");
	var type = $('header_search_type').value;
	if(search == "")
		search = "'";
	search = encodeURIComponent(search);
	if(type == 0){
		window.location.href = String.Format(electronicNameSearchUrl,search);
	}
	else if(type==2){
		window.location.href = String.Format(electronicMfgSearchUrl,search);
	}
	else{
		window.location.href = String.Format(newsTitleSearchUrl,search);
	}
}

function ReplaceSomeWord(str)
{
	str = str.replace('/','');
	str = str.replace('?','');
	str = str.replace('\\','');
	return str;
}

function SubmitPager(url,pageindex)
{
	window.location.href = String.Format(url,pageindex);
}

function InitSelected(id,value)
{
	var elem = document.getElementById(id);
	if(elem)
		elem.value = value;
}

function InitChecked(id,value)
{
	var elem = document.getElementById(id);
	if(elem){
		elem.checked = value;
	}
}

function ShowTopWindow(url,width,height)
{
	return window.showModalDialog(url,'','dialogWidth:'+width+'px;dialogHeight:'+height+'px;center:1;status=0;help:0;');
}

function ShowTopWindow2(url,args,width,height)
{
	return window.showModalDialog(url,args,'dialogWidth:'+width+'px;dialogHeight:'+height+'px;center:1;status=0;help:0;');
}

function opconfirm()
{
	return window.confirm('是否要执行操作?');
}

function confirmAndSubmit(f)
{
	if(opconfirm())
	{
		document.getElementById(f).submit();
	}
}

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 ResizeImageWH(ImgD,varPicMaxWidth1,varPicMaxHeight){ 
    var image=new Image(); 
    image.src=ImgD.src; 
//width
if((image.width/image.height)>=(varPicMaxWidth1/varPicMaxHeight)){
        if(image.width>=varPicMaxWidth1){ 
            ImgD.width=varPicMaxWidth1; 
            ImgD.height=(image.height*varPicMaxWidth1)/image.width; 
        }else{ 
            ImgD.width=image.width; 
            ImgD.height=image.height; 
        }
}
else
{
	if(image.height>=varPicMaxHeight){ 
            ImgD.height=varPicMaxHeight; 
            ImgD.width=(image.width*varPicMaxHeight)/image.height; 
        }else{ 
            ImgD.width=image.width; 
            ImgD.height=image.height; 
        }
}
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -