javascript一些不错的函数脚本代码
JavaScript代码 函数 脚本 一些 不错
2023-06-13 09:14:02 时间
计算字符长度的js函数
functionLEN(str){
vari,sum=0;
for(i=0;i<str.length;i++){
if((str.charCodeAt(i)>=0)&&(str.charCodeAt(i)<=255))
sum=sum+1;
else
sum=sum+2;
}
returnsum;
}
去字符中前后的空格的js函数
functionTRIM(value){returnvalue.replace(/^\s*/,"").replace(/\s*$/,"");}
图片自适应大小函数代码
functionimgAutoFit(imgObj,maxWidth,maxHeight){
varheightWidth;
varwidthHeight;
heightWidth=imgObj.offsetHeight/imgObj.offsetWidth;
widthHeight=imgObj.offsetWidth/imgObj.offsetHeight;
if(imgObj.offsetWidth>maxWidth){
imgObj.width=maxWidth;
imgObj.height=maxWidth*heightWidth;
}
if(imgObj.offsetHeight>maxHeight){
imgObj.height=maxHeight;
imgObj.width=maxHeight*widthHeight;
}
}
functioncheckTagIsHave(s,t){
varre=newRegExp("<\\/?"+t+"(?:(?:\\s|\\/)(?:\\n|.)*?)?>","ig");
varr=re.test(s);
re=null;
returnr;
}
functionimgUploadFit(){
varu=document.getElementsByName("imgUploadName");
if(0==u.length)return;
for(vari=0;i<u.length;i++){
//imgAutoFit(u[i],560,560);
imgAutoFit(u[i],320,320);
u[i].onclick=function(){window.open(this.src);}
u[i].style.cursor="pointer";
u[i].title="点击看原图";
}
}
functioninputContent(theQ,oldContent,re,p){
varo,oA=["msgframeamend","pingJiaFrame","touSuFrame"];
for(oinoA){
if($(oA[o])){
theQ.editIframe(oA[o]);
if("msgframeamend"==oA[o])setTimeout(function(){$(oA[o]).contentWindow.document.body.innerHTML=oldContent.replace(re,"")+p[1];},100);
return;
}
}
}
functioncheckCommon(n,v,t){
vars=t?"补充提问":"回复内容";
varo=document.getElementById(n).contentWindow;
if("msgframereply"==n){
if(v==""){
alert("请填写"+s+"!");
o.focus();
returnfalse;
}
}
if(""==v.replace(/<\/*?(?:img|p|pre|br)(?:(?:\s|\/)(?:\n|.)*?)?>|\s| /ig,"")&&checkTagIsHave(v,"img")){
alert("针对图片,请附上一些说明性的文字!");
o.focus();
returnfalse;
}
if(10000<LEN(v)){
alert(s+"超过5000字数限制!");
o.focus();
returnfalse;
}
returntrue;
}
相关文章
- 26行JavaScript代码 仿async的 并行执行和序列执行函数详解编程语言
- JavaScript实现Sleep函数的代码
- javascript状态栏的字符先杂乱出现再排列组合的代码
- javascript实现的鼠标链接提示效果生成器代码
- 给Javascript数组插入一条记录的代码
- javascript下过滤数组重复值的代码
- Javascript检测、添加、移除样式(className)函数代码
- javascript(jquery)利用函数修改全局变量的代码
- javascript代码在ie8里报错document.getElementById(...)为空或不是对象的解决方法原创
- javascript获取url参数和script标签中获取url参数函数代码
- 两个比较有用的Javascript工具函数代码
- javascript实现的像java、c#之类的sleep暂停的函数代码
- Javascript读取cookie函数代码
- 动态加载外部javascript文件的函数代码分享
- JavaScript选中文字并响应获取的实现代码
- javascript中将Object转换为String函数代码(jsonstr)
- Javascript面向对象(三)接口代码
- javascript判断中文字符长度的函数代码
- JavaScript操作table,可以新增行和列并且隔一行换背景色代码分享
- JavaScript判断密码强度(自写代码)
- javascript四舍五入函数代码分享(保留后几位)
- javascript实现页面内关键词高亮显示代码
- Javascript常用字符串判断函数代码分享
- JavaScript中判断原生函数检查function是否是原生代码
- javascript自定义回调函数示例代码