1、按比例缩放图片
ImgD:图片的Node
iwidth:缩放后的宽度
iheight:缩放后的高度
-
function DrawImage(ImgD,iwidth,iheight){
-
var flag=false
;
-
var image=new
Image();
-
var iwidth = iwidth;
-
var iheight = iheight;
-
image.src=ImgD.src;
-
if
(image.width>
0
&& image.height>
0
){
-
flag=true
;
-
if
(image.width/image.height>= iwidth/iheight){
-
if
(image.width>iwidth){
-
ImgD.width=iwidth;
-
ImgD.height=(image.height*iwidth)/image.width;
-
}else
{
-
ImgD.width=image.width;
-
ImgD.height=image.height;
-
}
-
}
-
else
{
-
if
(image.height>iheight){
-
ImgD.height=iheight;
-
ImgD.width=(image.width*iheight)/image.height;
-
}else
{
-
ImgD.width=image.width;
-
ImgD.height=image.height;
-
}
-
}
-
}
-
}
2、删除空格
-
-
function trim(str){
-
return
str.replace(/(^\s*)|(\s*$)/g,
""
);
-
}
-
-
function ltrim(str){
-
return
str.replace(/(^\s*)/g,
""
);
-
}
-
-
function rtrim(str){
-
return
str.replace(/(\s*$)/g,
""
);
-
}
3、删除回车符号
-
function trimEnter(str){
-
return
str.replace(/\n\r/gi,
""
);
-
}
-
注:2
、
3
均是Js中正则表达式的应用。
-
js中的replace()方法只能够替换掉出现该字符的第一位置处,所以可使用正则表达式来实现。
4、检测checkbox是否选中及可选中个数
allow=0,则不限制选中的个数
-
function chkCheckbox(checkboxName,allow){
-
var selectCount=0
;
-
var names=document.getElementsByName(checkboxName);
-
for
(var i=
0
;i<names.length;i++)
-
{
-
var box=names[i];
-
if
(box.type==
'checkbox'
){
-
if
(box.checked==
true
){
-
selectCount++;
-
}
-
}
-
}
-
if
(selectCount==
0
){
-
alert("请选择记录!"
);
-
return
;
-
}else
{
-
if
(allow>
0
){
-
if
(selectCount>allow){
-
alert("只允许选择"
+allow+
"条记录,请重新选择!"
);
-
return
;
-
}
-
}
-
}
-
return
true
;
-
}
5、弹出页面
-
function openWin(openUrl,width_1,height_1){
-
var left_1=(screen.width-width_1)/2
;
-
var top_1=(screen.Height-height_1)/2
;
-
var paramcon="?"
;
-
if
(openUrl.indexOf(
"?"
)>
0
) paramcon=
"&"
;
-
else
paramcon=
"?"
;
-
window.open(openUrl+paramcon+"random="
+Math.random(),
"newwindow"
,
"height="
+height_1+
", width="
+width_1+
", top="
+top_1+
", left="
+left_1+
", toolbar=mo,titlebar=yes, menubar=no, scrollbars=yes, resizable=yes,location=no, status=yes"
);
-
}
-
function openWinNo(openUrl,width_1,height_1){
-
var left_1=(screen.width-width_1)/2
;
-
var top_1=(screen.Height-height_1)/2
;
-
var paramcon="?"
;
-
if
(openUrl.indexOf(
"?"
)>
0
) paramcon=
"&"
;
-
else
paramcon=
"?"
;
-
window.open(openUrl+paramcon+"random="
+Math.random(),
"newwindow"
,
"height="
+height_1+
", width="
+width_1+
", top="
+top_1+
", left="
+left_1+
", toolbar=no,titlebar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no"
);
-
}
注:window.open(url,target,attribute);window.open()有三个参数.
url:即页面地址。
target:弹出目标。如果2个弹出页面都写成"newwindow",则只会看到后弹出页面的内容。
attribute:弹出窗口属性。
在被弹出来的页面中可以用window.opener得到上一个页面的window对象,同时也可以使用window里的所有东西。
如上个页面有function setAllValue();则在被弹出来的页面中可以window.opener.setAllValue();
6、模式窗口
-
function getModalDialog(openUrl){
-
var paramcon="?"
;
-
if
(openUrl.indexOf(
"?"
)>
0
) paramcon=
"&"
;
-
else
paramcon=
"?"
;
-
var info=new
Object();
-
info.dataInfo="test"
;
-
return
window.showModalDialog(openUrl+paramcon+
"random="
+Math.random(),info,
"dialogHeight: 380px; dialogWidth: 500px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;"
);
-
}
在打开来的页面中:
var oMyObject = window.dialogArguments;
可以使用oMyObject.dataInfo得到"test"字符串
window.parent.returnValue="test2";可以设置返回值。
注:showModalDialog(url,object,attribute)有3各参数
url:即要打开的网页地址,可以带参数。同样,url有长度限制,如需传递参数,可使用第二个参数。
object:传递给打开来的页面数据。如上例中的传递方法。
attribute:设置打开来的窗口属性。
模式窗口与window.open()不同。必须关闭模式窗口才能继续在本页面操作。
模式窗口有一定缓存,所以在url后边添加一个随机数。
分享到:
相关推荐
常用 javascript 大全 常用js大全
js,javascript,特效,常用js特效,javascript特效
JavaScript大全 常用JS效果代码,绝对物超所值
程序员 常用 JavaScript 特效 网页特效程序员 常用 JavaScript 特效 网页特效程序员 常用 JavaScript 特效 网页特效
常用JS代码提供下载常用JS代码提供下载常用JS代码提供下载常用JS代码提供下载常用JS代码提供下载
日常所用的JS JAVASRCIPT日常所用的JS JAVASRCIPT日常所用的JS JAVASRCIPT
常用js整理---常用js整理--常用js整理
1500个前端开发常用JavaScript特效1500个前端开发常用JavaScript特效1500个前端开发常用JavaScript特效1500个前端开发常用JavaScript特效1500个前端开发常用JavaScript特效1500个前端开发常用JavaScript特效1500个...
108个常用JS脚本.。。。比较实用··
泛微oa流程L流程表单常用js,主表、明细表、根据主表字段显示或隐藏明细表指定列、验证大小、如何实现登录名记住上次登录的登录名、如何给单元格添加链接【例如:获取快递单号】、复选框必须选择一个方可提交
73种网页常用js代码,转自某个群。目前还算挺实用的
107个常用Javascript语句.doc
常用js代码公用方法
收集统计了泛微OA Ecology流程表单的JS脚本,OA系统管理必备文档。可以参考PDF的文档学习一下,将它转变成自己的知识,后面就可以给泛微做系统维护人员,有事不求人哈……
常用Javascript特效代码集锦,带有演示,左侧是特效分类及名称,点击后在右侧窗口中可预览效果,点右键可查看源代码,非常方便,是网页编程及学习JS的好资料。这些特效涵盖图片特效、页面与背景特效、日期与...
W3Cfuns1500个前端开发常用JavaScript特效
2.JS 中的注释为// 3.传统的 HTML 文档顺序是:document->html->(head,body) 4.一个浏览器窗口中的 DOM 顺序是: window->(navigator,screen,history,location,document) 5.得到表单中元素的名称和值:document....
中创常用Js JavaScript大全,它是在实习时得到了,希望能够帮助到你
51CTO下载-1500个前端开发常用JavaScript特效