计算字符长度的js函数
复制代码 代码如下:
function LEN(str){
var i,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;
}
return sum;
}
去字符中前后的空格的js函数
复制代码 代码如下:
function TRIM(value){return value.replace(/^\s*/,'').replace(/\s*$/,''); }
图片自适应大小函数代码
复制代码 代码如下:
function imgAutoFit(imgObj,maxWidth,maxHeight){
var heightWidth;
var widthHeight;
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;
}
}
function checkTagIsHave(s,t){
var re=new RegExp("<\\/?"+t+"(?:(?:\\s|\\/)(?:\\n|.)*?)?>","ig");
var r=re.test(s);
re=null;
return r;
}
function imgUploadFit(){
var u = document.getElementsByName("imgUploadName");
if(0==u.length) return;
for(var i=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 = "点击看原图";
}
}
function inputContent(theQ,oldContent,re,p){
var o,oA=["msgframeamend","pingJiaFrame","touSuFrame"];
for(o in oA){
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;
}
}
}
function checkCommon(n,v,t){
var s = t?"补充提问":"回复内容";
var o=document.getElementById(n).contentWindow;
if("msgframereply" == n){
if(v == ""){
alert("请填写"+s+" !");
o.focus();
return false;
}
}
if(""==v.replace(/<\/*?(?:img|p|pre|br)(?:(?:\s|\/)(?:\n|.)*?)?>|\s| /ig,"")&&checkTagIsHave(v,"img")){
alert("针对图片,请附上一些说明性的文字!");
o.focus();
return false;
}
if(10000<LEN(v)){
alert(s+"超过5000字数限制 !");
o.focus();
return false;
}
return true;
}
javascript,函数
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。