2008-01-14
js积累
js清除字符串中所有空格:
xx=xx.replace(/\s/g,'');
js判断字符串中括号配对性:
if(mm.split(")").length != mm.split("(").length){
alert("手写公式中括号不匹配");
return false;
}
js分割字符串:
...
function OnCall()
...{
var aaa = "1|aaa|2|bbb|3|ccc|4|ddd|"
var bbb = aaa.split("|")
var count = (bbb.length-1)/2
for(var i=0; i<=count; i++)
...{
document.all("DropDownList2").options.add(new Option(bbb[i],bbb[i+1]));
}
return
javascript在不同页面间传值一例:
1.主页面:
var newwindow = '';
function popitup(url) {
if (!newwindow.closed && newwindow.location) {
newwindow.location.href = url;
}
else {
newwindow=window.open(url,'name','height=200,width=150');
if (!newwindow.opener) newwindow.opener = self;
}
if (window.focus) {newwindow.focus()}
return false;
}
popitup('2.html');
2.弹出页面:
。。。。。
3.说明:主要应用opener定位弹出窗口的父窗口。
js中的==和=,这个语法和java中应该是一样的,竟然用的不明不白的,没面子
javascript中在iframe调用会父页面的方法:
调用父页面的函数: (调用父页面的callback(xx)函数)
out.println("<script>parent.callback(1)</script>");
或者:(调用父页面的setPicurl)
function returnBack(a,b)
{
document.parentWindow.parent.setPicUrl(a,b);
}
从51js上一些比较有细节的收集:
只能输入汉字
<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
只能输入全角
<input onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))">
只能输入数字
<input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
只能输入英文和数字
<input onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
关闭父窗口(无提示)
<script>
opener="";
window.open().document.write("<input value='关闭父窗口' type='button' onclick='opener.window.close()'>");
</script>
让表格半透明
<body bgcolor="red">
This is body!
<div style="position:absolute;background:black;filter:Alpha(Opacity=50);color:white;height:300;top:0;left:0">This is layer!</div>
</body>
或
<body style="filter:Alpha(Opacity=50)">
<iframe width="100%" height="100%" src="http://sina.com.cn">
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>
<input name=Button onClick=document.all.WebBrowser.ExecWB(2,1) type=button value=关闭所有>
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为>
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印>
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印>
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置>
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性>
<input name=Button onClick=document.all.WebBrowser.ExecWB(17,1) type=button value=全选>
<input name=Button onClick=document.all.WebBrowser.ExecWB(22,1) type=button value=刷新>
<input name=Button onClick=document.all.WebBrowser.ExecWB(45,1) type=button value=关闭>
屏蔽 JS 错误
function killErrors() { return true; }
window.onerror = killErrors; dd
只在关闭窗口的时候提示,刷新的时候不提示
if(event.clientX>document.body.clientWidth)alert("你没有刷新就关闭了?");
js关闭Excel的一种方法:
<SCRIPT LANGUAGE=Javascript>
var idTmr = "";
function StartExcel() {
var oExcel;
oExcel = new ActiveXObject("Excel.Application");
oExcel.Quit();
oExcel = null;
idTmr = window.setInterval("Cleanup();",1);
}
function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
}
</SCRIPT>
待续。。。。。。
- 09:12
- 浏览 (83)
- 评论 (0)
- 分类: javascript
- 相关推荐
发表评论
- 浏览: 10669 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
我的相册
自行车
共 1 张
共 1 张
最近加入圈子
最新评论
-
HashMap使用
你就是在thinking in java 上下载的吧,不过总结的不错
-- by lysmart_8 -
过去有一位年轻和尚,一心 ...
哈哈哈,这个老和尚估计是个高级“和尚”
-- by hydex -
不规范的树结构表查询
一个值得读一下的文章:http://www.itpub.net/redirect ...
-- by hydex






评论排行榜