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>

 

 

待续。。。。。。

 

评论
发表评论

您还没有登录,请登录后发表评论

hydex
搜索本博客
我的相册
5e0be7a5-3ea9-31fe-a7c4-7a19f3b7d537-thumb
自行车
共 1 张
存档
最新评论