常用JavaScript函数1-15.doc
上传人:sy****28 上传时间:2024-09-14 格式:DOC 页数:16 大小:198KB 金币:16 举报 版权申诉
预览加载中,请您耐心等待几秒...

常用JavaScript函数1-15.doc

常用JavaScript函数1-15.doc

预览

免费试读已结束,剩余 6 页请下载文档后查看

16 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

1、调整图片大小,不走形(FFIE兼容)2、控制textarea区域文字数量3、点击显示新窗口4、input框自动随内容自动变长5、添加收藏夹6、设置首页7、Jquery+Ajax判断用户是否存在8、判断email格式是否正确9、综合判断用户名(长度,英文字段等)10、新闻滚动11、只允许输入正整数(shoppingcart使用)12、转换字符串为数字13、判断文件格式(获得文件后缀)14、截取字符串15、分割字符串1、调整图片大小,不走形(FFIE兼容)Js代码//用法<imgsrc="this_image_path.jpg"onload="DrawImage(this,450,450);"/>functionDrawImage(ImgD,FitWidth,FitHeight){varimage=newImage();image.src=ImgD.src;if(image.width>0&&image.height>0){if(image.width/image.height>=FitWidth/FitHeight){if(image.width>FitWidth){ImgD.width=FitWidth;ImgD.height=(image.height*FitWidth)/image.width;}else{ImgD.width=image.width;ImgD.height=image.height;}}else{if(image.height>FitHeight){ImgD.height=FitHeight;ImgD.width=(image.width*FitHeight)/image.height;}else{ImgD.width=image.width;ImgD.height=image.height;}}}}//用法<imgsrc="this_image_path.jpg"onload="DrawImage(this,450,450);"/>functionDrawImage(ImgD,FitWidth,FitHeight){varimage=newImage();image.src=ImgD.src;if(image.width>0&&image.height>0){if(image.width/image.height>=FitWidth/FitHeight){if(image.width>FitWidth){ImgD.width=FitWidth;ImgD.height=(image.height*FitWidth)/image.width;}else{ImgD.width=image.width;ImgD.height=image.height;}}else{if(image.height>FitHeight){ImgD.height=FitHeight;ImgD.width=(image.width*FitHeight)/image.height;}else{ImgD.width=image.width;ImgD.height=image.height;}}}}2、控制textarea区域文字数量Js代码//eg:<textareaid="sms"name="sms"maxlength="50"onkeyup="getLength(document.getElementById('sms').value,50);"></textarea><pid="p1"></p>vartemp;functiongetLength(content,length){temp=content;vartext=content.replace(/[^\x00-\xff]/g,"**");varlength1=text.length;if(length>=length1){document.getElementById("p1").innerHTML="Remainingcharactercount:"+(length-length1);}else{document.getElementById('sms').value=getShortForm(document.getElementById('sms').value,length,"");document.getElementById("p