JS技巧

平面输入框
<input type="text" name="T1" size="20" style="border-style: solid; border-width: 1">

使文字上下滚动
<marquee direction=up scrollamount=1 scrolldelay=100 οnmοuseοver='this.stop()' οnmοuseοut='this.start()' height=60>
<!-- head_scrolltext -->
<table>
<tr>
<td>
共和国
</td>
</tr>
</table>
 <!-- end head_scrolltext -->     
</marquee>

显示文档最后修改日期
<script language=javascript>
function hi(str)
{
 document.write(document.lastModified)

 alert("hi"+str+"!")
}
</script>

打印网页
<a href='javascript:window.print ()'>打印</a>

改变下拉框的颜色
<select name="classid"

onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)"

size="1" style="color:#008080;font-size: 9pt">

将页面加入favorite中
<script language=javascript>
<!--
function Addme(){
url = "http://your.site.address"; //你自己的主页地址
title = "Your Site Name"; //你自己的主页名称
window.external.AddFavorite(url,title);
-->
</script>

在网页上显示实时时间
<SCRIPT LANGUAGE="JavaScript">
var clock_id;
window.οnlοad=function()
{
 clock_id=setInterval("document.form1.txtclock.value=(new Date);",1000)
}
</SCRIPT>

同时按下CTRL和Q键
document.οnkeydοwn=function()
{
if(event.ctrlKey&&event.keyCode==81)
{alert(1)}
}

复制内容到剪切板
function JM_cc(bb)
{
    var ob=eval("document.form1."+bb);
    ob.select();
    js=ob.createTextRange();
    js.execCommand("Copy");
}

最小化窗口
window.blur()

设置为主页
function makeHome(){
  netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
  navigator.preference("browser.startup.homepage", location.href);
}

设置为收藏
function addFav(){
  if(ie)
    window.external.AddFavorite(location.href,'WWW.OGRISH.COM : GROTESQUE MOVIES AND PICTURES');
  if(ns)
    alert("Thanks for the bookmark!\n\nNetscape users click OK then press CTRL-D");
}

判断cookie是否可用
navigator.cookieEnabled;

禁止选择页面上的文字来拷贝
<script>
function noEffect() {
  with (event) {
    returnValue = false;
    cancelBubble = true;
  }
  return;
}
</script>
<body onselectstart="noEffect()" οncοntextmenu="noEffect()">

屏蔽右键菜单
οncοntextmenu="event.returnValue = false"

禁止在输入框打开输入法
<input style="ime-mode: disabled">

屏蔽汉字和空格
<input name="txt"><input type="submit" onClick="alert(!/[^ -}]|\s/.test(txt.value))">

用javascript判断文件是否存在
function Exists(filespec)
{
 if (filespec)
 {
  var fso;
  fso = new ActiveXObject("Scripting.FileSystemObject");
  alert(fso.FileExists(filespec));
 }
}
选择图片 <input type=file name=f1><p>
<input type="submit" onClick="Exists(f1.value)">

获得当前的行是表格的第几行
<script>
function getrow(obj)
{
   if(event.srcElement.tagName=="TD"){
   curRow=event.srcElement.parentElement;
   alert("这是第"+(curRow.rowIndex+1)+"行");

   }
}
</script>

<table border="1" width="100%" οnclick=getrow(this)>
  <tr>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
  </tr>
  <tr>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
  </tr>
</table>

删除表格某行,xx表示某行,下标从0开始计算
document.all.myTable.deleteRow(xx)

动态的向表格中添加行
<table id="t1" border="1">
</table>
<script language="JavaScript">
function add()
{
   t1.insertRow().insertCell().innerHTML = '<input name="test'+t1.rows.length+'">';
}

将页面上选中的内容复制到剪贴板
abcdefg
<input type='button'

οnclick="window.clipboardData.setData('text',document.selection.createRange().text);" value='复制页面选中的字符'>

将页面上选中的内容复制到剪贴板
<INPUT TYPE="text" NAME="">kjhkjhkhkj<INPUT TYPE="button" οnclick="document.execCommand('Copy', 'false', null);">

获得本机的文件
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f1 = fso.GetFile("C:\\bsitcdata\\ejbhome.xml");
alert("File last modified: " + f1.DateLastModified);

鼠标移到下拉框时自动全部打开
<select οnmοuseοver="javascript:this.size=this.length" οnmοuseοut="javascript:this.size=1"></select>

判断客户端是否是IE浏览器
因为 document.all 是 IE 的特有属性,所以通常用这个方法来判断客户端是否是IE浏览器 ,document.all?1:0;

在页面上画柱状图
<STYLE>
td{font-size:12px}
body{font-size:12px}
v\:*{behavior:url(#default#VML);} //这里声明了v作为VML公用变量
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
mathstr=12;
document.write ("<v:rect fillcolor='red'

style='width:20;color:navy;height:"+5000/(1000/mathstr)+"'><br>&nbsp;%"+mathstr+"<br>4人<v:Extrusion

backdepth='15pt' on='true'/></v:rect>")
</SCRIPT>
<v:rect fillcolor='red' style='width:20;color:navy;height:200'><br>%12<br>4人<v:Extrusion

backdepth='15pt' on='true'/></v:rect>
<v:rect fillcolor='yellow' style='width:20;color:navy;height:100'><br>%12<br>4人<v:Extrusion

backdepth='15pt' on='true'/></v:rect>

饼图
<style>
v\:*     { behavior: url(#default#VML) }
o\:*     { behavior: url(#default#VML) }
.shape    { behavior: url(#default#VML) }
</style>
<script language="javascript">
function show(pie)
{
pie.strokecolor=pie.fillcolor;
pie.strokeweight=10;
div1.innerHTML="<font size=2 color=red> " + pie.id +"</font> <font size=2>" + pie.title + "</font>";
}
function hide(pie)
{
pie.strokecolor="white";
pie.strokeweight=1;
div1.innerHTML="";
}
</script>
</head>
<body>
<v:group style='width: 5cm; height: 5cm' coordorigin='0,0' coordsize='250,250'>
<v:shape id='asp技术' style='width:10;height:10;top:10;left:0' title='得票数:6 比例:40.00%'

οnmοuseοver='javascript:show(this);' οnmοuseοut='javascript:hide(this);' href='http://www.cnADO.com'

CoordSize='10,10' strokecolor='white' fillcolor='#ffff33'><v:path v='m 300,200 ae

300,200,200,150,0,9437184 xe'/></v:shape>
<v:shape id='php' style='width:10;height:10;top:10;left:0' title='得票数:1 比例:6.67%'

οnmοuseοver='javascript:show(this);' οnmοuseοut='javascript:hide(this);' href='http://www.cnADO.com'

CoordSize='10,10' strokecolor='white' fillcolor='#ff9933'><v:path v='m 300,200 ae

300,200,200,150,9437184,1572864 xe'/></v:shape>
<v:shape id='jsp' style='width:10;height:10;top:10;left:0' title='得票数:2 比例:13.33%'

οnmοuseοver='javascript:show(this);' οnmοuseοut='javascript:hide(this);' href='http://www.cnADO.com'

CoordSize='10,10' strokecolor='white' fillcolor='#3399ff'><v:path v='m 300,200 ae

300,200,200,150,11010048,3145728 xe'/></v:shape>
<v:shape id='c#写的.netWEB程序' style='width:10;height:10;top:10;left:0' title='得票数:3 比例:20.00%'

οnmοuseοver='javascript:show(this);' οnmοuseοut='javascript:hide(this);' href='http://www.cnADO.com'

CoordSize='10,10' strokecolor='white' fillcolor='#99ff33'><v:path v='m 300,200 ae

300,200,200,150,14155776,4718592 xe'/></v:shape>
<v:shape id='vb.net写的.netWEB程序' style='width:10;height:10;top:10;left:0' title='得票数:2 比例:13.33%'

οnmοuseοver='javascript:show(this);' οnmοuseοut='javascript:hide(this);' href='http://www.cnADO.com'

CoordSize='10,10' strokecolor='white' fillcolor='#ff6600'><v:path v='m 300,200 ae

300,200,200,150,18874368,3145728 xe'/></v:shape>
<v:shape id='xml技术' style='width:10;height:10;top:10;left:0' title='得票数:1 比例:6.67%'

οnmοuseοver='javascript:show(this);' οnmοuseοut='javascript:hide(this);' href='http://www.cnADO.com'

CoordSize='10,10' strokecolor='white' fillcolor='#ff99ff'><v:path v='m 300,200 ae

300,200,200,150,22020096,1572864 xe'/></v:shape>
</v:group>

<v:group style='width: 6cm; height: 6cm' coordorigin='0,0' coordsize='250,250'>
<v:rect style='height:10;width:15;top:0;left:10' fillcolor='#ffff33'/>
<v:rect style='height:28;width:100;top:0;left:30' stroked='false'><v:textbox

style='fontsize:2'>asp技术</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:30;left:10' fillcolor='#ff9933'/>
<v:rect style='height:28;width:100;top:30;left:30' stroked='false'><v:textbox

style='fontsize:2'>php</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:60;left:10' fillcolor='#3399ff'/>
<v:rect style='height:28;width:100;top:60;left:30' stroked='false'><v:textbox

style='fontsize:2'>jsp</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:90;left:10' fillcolor='#99ff33'/>
<v:rect style='height:28;width:100;top:90;left:30' stroked='false'><v:textbox

style='fontsize:2'>c#写的.netWEB程序</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:120;left:10' fillcolor='#ff6600'/>
<v:rect style='height:28;width:100;top:120;left:30' stroked='false'><v:textbox style='fontsize:2'>vb.net

写的.netWEB程序</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:150;left:10' fillcolor='#ff99ff'/>
<v:rect style='height:28;width:100;top:150;left:30' stroked='false'><v:textbox style='fontsize:2'>xml技术

</v:textbox/></v:rect>
</v:group>

<div style="position: absolute; left: 10; top: 10; width: 760; height:16">
 <table border="1" cellpadding="2" cellspacing="2" cellpadding="0" cellspacing="0"

style="border-collapse: collapse" bordercolor="#CCCCCC" width="100%" ID="Table1">
  <tr>
   <td width="100%" id=div1> </td>
  </tr>
 </table>
</div>

交换节点
<table  width=200  height=200  border>
<tr><td  id=c1>CELL_1</td></tr>
<tr><td  id=c2>CELL_2</td></tr>
</table>
<br>
<input  type="button"  value="swap  row"  οnclick="c1.swapNode(c2)">

删除节点
<table  width=200  height=200  border>
<tr id=trall><td  id=c1>CELL_1</td></tr>
<tr><td  id=c2>CELL_2</td></tr>
</table>
<br>
<input  type="button"  value="swap  row"  οnclick="trall.removeNode(c2)">

添加节点
addNode()

获得事件的父与子标签
event.srcElement.children[0]和event.srcElement.parentElement

判断是左键还是右键被按下
<body οnmοusedοwn=if(event.button==1)alert("左键");if(event.button==2)alert("右键")>

alt/ctrl/shift键按下
event.altKey //按下alt键
event.ctrlKey //按下ctrl键
event.shiftKey //按下shift键

读取XML文件
var childrenobj=myselect//document.all.myselect;
    var oXMLDoc = new ActiveXObject('MSXML');
    oXMLDoc.url = "mymsg.xml";
    var oRoot=oXMLDoc.root;
    if(oRoot.children != null)
 {
        for(var i=0;i<oRoot.children.item(0).children.length;++i)
  {
            oItem = oRoot.children.item(0).children.item(i);
            oOption = new Option(oItem.text,oItem.value);
   childrenobj.add(oOption);
        }
    }
//mymsg.xml文件
<?xml version="1.0" encoding="gb2312" ?>
<childrenlist>
<aa>
<child value='3301'>杭州地区</child>

<child value='3303'>温州地区</child>

</aa>
<aa>
<child value='3310'>台州地区</child>

<child value='3311'>丽水地区</child>
</aa>
</childrenlist>

给类定义新的方法
function trim_1()
{
  return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.trim=trim_1;
alert('cindy'.trim());

实现打印预览及打印
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<input type=button value=打印预览 οnclick="wb.execwb(7,1)">
<input type=button onClick=document.all.wb.ExecWB(6,1) value="打印">

使鼠标滚轮失效
function document.onmousewheel()
{
 return false;
}

创建弹出窗口
<SCRIPT LANGUAGE="JScript">
  var oPopup = window.createPopup();
  var oPopupBody = oPopup.document.body;
  oPopupBody.innerHTML = "Display some <B>HTML</B> here.";
  oPopup.show(100, 100, 200, 50, document.body);
</SCRIPT>

取得鼠标所在处的对象
var obj = document.elementFromPoint(event.x,event.y);

将数字转化为人民币大写形式
function convertCurrency(currencyDigits) {
// Constants:
 var MAXIMUM_NUMBER = 99999999999.99;
 // Predefine the radix characters and currency symbols for output:
 var CN_ZERO = "零";
 var CN_ONE = "壹";
 var CN_TWO = "贰";
 var CN_THREE = "叁";
 var CN_FOUR = "肆";
 var CN_FIVE = "伍";
 var CN_SIX = "陆";
 var CN_SEVEN = "柒";
 var CN_EIGHT = "捌";
 var CN_NINE = "玖";
 var CN_TEN = "拾";
 var CN_HUNDRED = "佰";
 var CN_THOUSAND = "仟";
 var CN_TEN_THOUSAND = "万";
 var CN_HUNDRED_MILLION = "亿";
 var CN_SYMBOL = "人民币";
 var CN_DOLLAR = "元";
 var CN_TEN_CENT = "角";
 var CN_CENT = "分";
 var CN_INTEGER = "整";
 
// Variables:
 var integral; // Represent integral part of digit number.
 var decimal; // Represent decimal part of digit number.
 var outputCharacters; // The output result.
 var parts;
 var digits, radices, bigRadices, decimals;
 var zeroCount;
 var i, p, d;
 var quotient, modulus;
 
// Validate input string:
 currencyDigits = currencyDigits.toString();
 if (currencyDigits == "") {
  alert("Empty input!");
  return "";
 }
 if (currencyDigits.match(/[^,.\d]/) != null) {
  alert("Invalid characters in the input string!");
  return "";
 }
 if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
  alert("Illegal format of digit number!");
  return "";
 }
 
// Normalize the format of input digits:
 currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
 currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
 // Assert the number is not greater than the maximum number.
 if (Number(currencyDigits) > MAXIMUM_NUMBER) {
  alert("Too large a number to convert!");
  return "";
 }
 
// http://www.knowsky.com/ Process the coversion from currency digits to characters:
 // Separate integral and decimal parts before processing coversion:
 parts = currencyDigits.split(".");
 if (parts.length > 1) {
  integral = parts[0];
  decimal = parts[1];
  // Cut down redundant decimal digits that are after the second.
  decimal = decimal.substr(0, 2);
 }
 else {
  integral = parts[0];
  decimal = "";
 }
 // Prepare the characters corresponding to the digits:
 digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT,

CN_NINE);
 radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
 bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
 decimals = new Array(CN_TEN_CENT, CN_CENT);
 // Start processing:
 outputCharacters = "";
 // Process integral part if it is larger than 0:
 if (Number(integral) > 0) {
  zeroCount = 0;
  for (i = 0; i < integral.length; i++) {
   p = integral.length - i - 1;
   d = integral.substr(i, 1);
   quotient = p / 4;
   modulus = p % 4;
   if (d == "0") {
    zeroCount++;
   }
   else {
    if (zeroCount > 0)
    {
     outputCharacters += digits[0];
    }
    zeroCount = 0;
    outputCharacters += digits[Number(d)] + radices[modulus];
   }
   if (modulus == 0 && zeroCount < 4) {
    outputCharacters += bigRadices[quotient];
   }
  }
  outputCharacters += CN_DOLLAR;
 }
 // Process decimal part if there is:
 if (decimal != "") {
  for (i = 0; i < decimal.length; i++) {
   d = decimal.substr(i, 1);
   if (d != "0") {
    outputCharacters += digits[Number(d)] + decimals[i];
   }
  }
 }
 // Confirm and return the final output string:
 if (outputCharacters == "") {
  outputCharacters = CN_ZERO + CN_DOLLAR;
 }
 if (decimal == "") {
  outputCharacters += CN_INTEGER;
 }
 outputCharacters = CN_SYMBOL + outputCharacters;
 return outputCharacters;
}

XML操作
<xml id="xmldata" src="/data/books.xml">
<div id="guoguo"></div>
<script>
var x=xmldata.recordset //取得数据岛中的记录集
if(x.absoluteposition < x.recordcount) //如果当前的绝对位置在最后一条记录之前
{
 x.movenext();     //向后移动
 x.moveprevious();    //向前移动
 x.absoluteposition=1;   //移动到第一条记录
 x.absoluteposition=x.recordcount;//移动到最后一条记录,注意记录集x.absoluteposition是从1到记录集记录的个数的
 guoguo.innerText=xmldso.recordset("field_name"); //从中取出某条记录
}
</script>

动态修改CSS的另一种方式
this.runtimeStyle.cssText = "color:#990000;border:1px solid #cccccc";

设置和使用cookie
<HTML>
<BODY>
设置与读取 cookies...<BR>
写入cookie的值<input type=text name=gg>
<INPUT TYPE = BUTTON Value = "设置cookie" onClick = "Set()">
<INPUT TYPE = BUTTON Value = "读取cookie" onClick = "Get()"><BR>
<INPUT TYPE = TEXT NAME = Textbox>
</BODY>
<SCRIPT LANGUAGE="JavaScript">
function Set()
{
var Then = new Date()
Then.setTime(Then.getTime() + 60*1000 ) //60秒
document.cookie = "Cookie1="+gg.value+";expires="+ Then.toGMTString()
}

function Get()
{
 var cookieString = new String(document.cookie)
 var cookieHeader = "Cookie1="
 var beginPosition = cookieString.indexOf(cookieHeader)
 if (beginPosition != -1)
 {
  document.all.Textbox.value = cookieString.substring(beginPosition  + cookieHeader.length)
 }
 else
  document.all.Textbox.value = "Cookie 未找到!"
}
</SCRIPT>
</HTML>

取月的最后一天
function getLastDay(year,month)
{
 //取年
 var new_year = year;
 //取到下一个月的第一天,注意这里传入的month是从1~12
 var new_month = month++;
 //如果当前是12月,则转至下一年
 if(month>12)
 {
  new_month -=12;
  new_year++;
 }
 var new_date = new Date(new_year,new_month,1);
 return (new Date(new_date.getTime()-1000*60*60*24)).getDate();
}

【文件(F)】菜单中的命令的实现

1、〖打开〗命令的实现
[格式]:document.execCommand("open")
[说明]这跟VB等编程设计中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。
[举例]在<body></body>之间加入:
<a href="###" οnclick=document.execCommand("open")>打开</a>

2、〖使用 记事本 编辑〗命令的实现
[格式]:location.replace("view-source:"+location)
[说明]打开记事本,在记事本中显示该网页的源代码。
[举例]在<body></body>之间加入:
<a href="###" οnclick=location.replace("view-source:"+location)>使用 记事本编辑</a>

3、〖另存为〗命令的实现
[格式]:document.execCommand("saveAs")
[说明]将该网页保存到本地盘的其它目录!
[举例]在<body></body>之间加入:
<a href="###" οnclick=document.execCommand("saveAs")>另存为</a>

4、〖打印〗命令的实现
[格式]:document.execCommand("print")
[说明]当然,你必须装了打印机!
[举例]在<body></body>之间加入:
<a href="###" οnclick=document.execCommand("print")>打印</a>

5、〖关闭〗命令的实现
[格式]:window.close();return false
[说明]将关闭本窗口。
[举例]在<body></body>之间加入:
<a href="###" οnclick=window.close();return false)>关闭本窗口</a>

【编辑(E)】菜单中的命令的实现

〖全选〗命令的实现
[格式]:document.execCommand("selectAll")
[说明]将选种网页中的全部内容!
[举例]在<body></body>之间加入:
<a href="###" οnclick=document.execCommand("selectAll")>全选</a>

【查看(V)】菜单中的命令的实现

1、〖刷新〗命令的实现
[格式]:location.reload() 或 history.go(0)
[说明]浏览器重新打开本页。
[举例]在<body></body>之间加入:
<a href="###" οnclick=location.reload()>刷新</a>
或加入:
<a href="###" οnclick=history.go(0)>刷新</a>

2、〖源文件〗命令的实现
[格式]:location.replace("view-source:"+location)
[说明]查看该网页的源代码。
[举例]在<body></body>之间加入:
<a href="###" οnclick=location.replace("view-source:"+location)>查看源文件</a>

3、〖全屏显示〗命令的实现
[格式]:window.open(document.location, "url", "fullscreen")
[说明]全屏显示本页。
[举例]在<body></body>之间加入:
<a href="###" οnclick=window.open(document.location,"url","fullscreen")>全屏显示</a>

【收藏(A)】菜单中的命令的实现

1、〖添加到收藏夹〗命令的实现
[格式]:window.external.AddFavorite('url', '"网站名")
[说明]将本页添加到收藏夹。
[举例]在<body></body>之间加入:
<a href="javascript:window.external.AddFavorite('http://oh.jilinfarm.com', '胡明新的个人主页')">添加到收

藏夹</a>

2、〖整理收藏夹〗命令的实现
[格式]:window.external.showBrowserUI("OrganizeFavorites",null)
[说明]打开整理收藏夹对话框。
[举例]在<body></body>之间加入:
<a href="###" οnclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夹</a>

【工具(T)】菜单中的命令的实现

〖internet选项〗命令的实现
[格式]:window.external.showBrowserUI("PrivacySettings",null)
[说明]打开internet选项对话框。
[举例]在<body></body>之间加入:
<a href="###" οnclick=window.external.showBrowserUI("PrivacySettings",null)>internet选项</a>

【工具栏】中的命令的实现

1、〖前进〗命令的实现
[格式]history.go(1) 或 history.forward()
[说明]浏览器打开后一个页面。
[举例]在<body></body>之间加入:
<a href="###" οnclick=history.go(1)>前进</a>
或加入:
<a href="###" οnclick=history.forward()>前进</a>

2、〖后退〗命令的实现
[格式]:history.go(-1) 或 history.back()
[说明]浏览器返回上一个已浏览的页面。
[举例]在<body></body>之间加入:
<a href="###" οnclick=history.go(-1)>后退</a>
或加入:
<a href="###" οnclick=history.back()>后退</a>

3、〖刷新〗命令的实现
[格式]:document.reload() 或 history.go(0)
[说明]浏览器重新打开本页。
[举例]在<body></body>之间加入:
<a href="###" οnclick=location.reload()>刷新</a>
或加入:
<a href="###" οnclick=history.go(0)>刷新</a>

其它命令的实现
〖定时关闭本窗口〗命令的实现
[格式]:settimeout(window.close(),关闭的时间)
[说明]将关闭本窗口。
[举例]在<body></body>之间加入:
<a href="###" οnclick=settimeout(window.close(),3000)>3秒关闭本窗口</a>

加为首页
<SCRIPT>
function fnSet(){
oHomePage.setHomePage(location.href);
event.returnValue = false;
}
</SCRIPT>
<IE:HOMEPAGE ID="oHomePage" style="behavior:url(#default#homepage)"/>

防止链接文字折行
document.body.noWrap=true;

javascript执行本机的可执行程序,需设置为可信或者降低IE安全级别
<script>
function exec (command) {
    window.oldOnError = window.onerror;
    window._command = command;
    window.onerror = function (err) {
      if (err.indexOf('utomation') != -1) {
        alert('命令已经被用户禁止!');
        return true;
      }
      else return false;
    };
    var wsh = new ActiveXObject('WScript.Shell');
    if (wsh)
      wsh.Run(command);
    window.onerror = window.oldOnError;
  }
</script>
调用方式
<a href="javascript:" οnclick="exec('D:/test.bat')">测试</a>

弹出新页面,关闭旧页面,不弹出提示框
 var w=screen.availWidth-10;
   var h=screen.availHeight-10;
   var swin=window.open("/mc/mc/message_management.jsp",

"BGSMbest","scrollbars=yes,status,location=0,menubar=0,toolbar=0,resizable=no,top=0,left=0,height="+h+",w

idth="+w);
   window.opener=null;
   window.close();

能输入的下拉框
<span>
<input name="Department1" id="Department1" style=" border-right:0;width:130" autocomplete="off">
<span style="width:150;overflow:hidden">
<select  style="width:150;margin-left:-130" onChange="Department1.value=value">
<option value=""></option>
<option value="asdfasfadf">asdfasfadf</option>
<option value="546546">546546</option></select>

在方法中定义全局变量
function globalVar (script) {
        eval(script);//all navigators
  //window.execScript(script); //for ie only
}
globalVar('window.haha = "../system";');
alert(haha);//在方法中定义全局变量,其中的haha就是全局变量了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值