有用的javascript


有用的javascript
字体大小: 小 中 大
1.οncοntextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
 <table border οncοntextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制

3. οnpaste="return false" 不准粘贴

4. οncοpy="return false;" oncut="return false;" 防止复制

5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标

6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标

7. <input style="ime-mode:disabled"> 关闭输入法

8. 永远都会带着框架
<script language="JavaScript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
// --></script>

9. 防止被人frame
<SCRIPT LANGUAGE=JAVASCRIPT><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>

10. 网页将不能被另存为
<noscript><iframe src=*.html></iframe></noscript>

11. <input type=button value=查看网页源代码
οnclick="window.location = "view-source:"+ "http://www.pconline.com.cn"">

12.删除时确认
<a href="javascript:if(confirm("确实要删除吗?"))location="boos.asp?&areyou=删除&page=1"">删除</a>

13. 取得控件的绝对位置
//Javascript
<script language="Javascript">
function getIE(e){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
}
alert("top="+t+"/nleft="+l);
}
</script>

//VBScript
<script language="VBScript"><!--
function getIE()
dim t,l,a,b
set a=document.all.img1
t=document.all.img1.offsetTop
l=document.all.img1.offsetLeft
while a.tagName<>"BODY"
set a = a.offsetParent
t=t+a.offsetTop
l=l+a.offsetLeft
wend
msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
end function
--></script>

14. 光标是停在文本框文字的最后
<script language="javascript">
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart("character",e.value.length);
r.collapse(true);
r.select();
}
</script>
<input type=text name=text1 value="123" οnfοcus="cc()">

15. 判断上一页的来源
javascript:
document.referrer

16. 最小化、最大化、关闭窗口
<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize"></object>
<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Maximize"></object>
<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAM NAME="Command" VALUE="Close"></OBJECT>
<input type=button value=最小化 οnclick=hh1.Click()>
<input type=button value=最大化 οnclick=hh2.Click()>
<input type=button value=关闭 οnclick=hh3.Click()>
本例适用于IE


17.屏蔽功能键Shift,Alt,Ctrl
<script>
function look(){
if(event.shiftKey)
alert("禁止按Shift键!"); //可以换成ALT CTRL
}
document.οnkeydοwn=look;
</script>

18. 网页不会被缓存
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
或者<META HTTP-EQUIV="expires" CONTENT="0">

19.怎样让表单没有凹凸感?
<input type=text style="border:1 solid #000000">

<input type=text style="border-left:none; border-right:none; border-top:none; border-bottom:

1 solid #000000"></textarea>

20.<div><span>&<layer>的区别?
<div>(division)用来定义大段的页面元素,会产生转行
<span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行
<layer>是ns的标记,ie不支持,相当于<div>

 


21.让弹出窗口总是在最上面:
<body οnblur="this.focus();">

22.不要滚动条?
让竖条没有:
<body style="overflow:scroll;overflow-y:hidden">
</body>
让横条没有:
<body style="overflow:scroll;overflow-x:hidden">
</body>
两个都去掉?更简单了
<body scroll="no">
</body>

23.怎样去掉图片链接点击后,图片周围的虚线?
<a href="#" onFocus="this.blur()"><img src="logo.jpg" border=0></a>

24.电子邮件处理提交表单
<form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain">
<input type=submit>
</form>

25.在打开的子窗口刷新父窗口的代码里如何写?
window.opener.location.reload()

26.如何设定打开页面的大小
<body οnlοad="top.resizeTo(300,200);">
打开页面的位置<body οnlοad="top.moveBy(300,200);">

27.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动
<STYLE>
body
{background-image:url(logo.gif); background-repeat:no-repeat;
background-position:center;background-attachment: fixed}
</STYLE>

28. 检查一段字符串是否全由数字组成
<script language="Javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>

29. 获得一个窗口的大小
document.body.clientWidth; document.body.clientHeight

30. 怎么判断是否是字符
if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");
else alert("全是字符");

31.TEXTAREA自适应文字行数的多少
<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">
</textarea>


32. 日期减去天数等于第二个日期
<script language=Javascript>
function cc(dd,dadd)
{
//可以加上错误处理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
}
cc("12/23/2002",2)
</script>

33. 选择了哪一个Radio
<HTML><script language="vbscript">
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
next
end function
</script><BODY>
<INPUT name="radio1" type="radio" value="style" checked>Style
<INPUT name="radio1" type="radio" value="barcode">Barcode
<INPUT type="button" value="check" οnclick="checkme()">
</BODY></HTML>

34.脚本永不出错
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide
function killErrors() {
return true;
}
window.onerror = killErrors;
// -->
</SCRIPT>

35.ENTER键可以让光标移到下一个输入框
<input οnkeydοwn="if(event.keyCode==13)event.keyCode=9">

36. 检测某个网站的链接速度:
把如下代码加入<body>区域中:
<script language=Javascript>
tim=1
setInterval("tim++",100)
b=1
var autourl=new Array()
autourl[1]="www.njcatv.net"
autourl[2]="javacool.3322.net"
autourl[3]="www.sina.com.cn"
autourl[4]="www.nuaa.edu.cn"
autourl[5]="www.cctv.com"
function butt(){
document.write("<form name=autof>")
for(var i=1;i<autourl.length;i++)
document.write("<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text
name=url"+i+" size=40> =》<input type=button value=GO

οnclick=window.open(this.form.url"+i+".value)><br>")
document.write("<input type=submit value=刷新></form>")
}
butt()
function auto(url){
document.forms[0]["url"+b].value=url
if(tim>200)
{document.forms[0]["txt"+b].value="链接超时"}
else
{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}
b++
}
function run(){for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl+"/"+Math.random()+" width=1 height=1

οnerrοr=auto("http://"+autourl+"")>")}
run()</script>

37. 各种样式的光标
auto :标准光标
default :标准箭头
hand :手形光标
wait :等待光标
text :I形光标
vertical-text :水平I形光标
no-drop :不可拖动光标
not-allowed :无效光标
help :?帮助光标
all-scroll :三角方向标
move :移动标
crosshair :十字标
e-resize
n-resize
nw-resize
w-resize
s-resize
se-resize
sw-resize


38.页面进入和退出的特效
进入页面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">
推出页面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)"> 
这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使用哪种特效,取值为1-23:
  0 矩形缩小
  1 矩形扩大
  2 圆形缩小
  3 圆形扩大
  4 下到上刷新
  5 上到下刷新
  6 左到右刷新
  7 右到左刷新
  8 竖百叶窗
  9 横百叶窗
  10 错位横百叶窗
  11 错位竖百叶窗
  12 点扩散
  13 左右到中间刷新
  14 中间到左右刷新
  15 中间到上下
  16 上下到中间
  17 右下到左上
  18 右上到左下
  19 左上到右下
  20 左下到右上
  21 横条
  22 竖条
  23 以上22种随机选择一种

39.在规定时间内跳转
<META http-equiv=V="REFRESH" content="5;URL=http://www.51js.com">

40.网页是否被检索
<meta name="ROBOTS" content="属性值">
  其中属性值有以下一些:
  属性值为"all": 文件将被检索,且页上链接可被查询;
  属性值为"none": 文件不被检索,而且不查询页上的链接;
  属性值为"index": 文件将被检索;
  属性值为"follow": 查询页上的链接;
  属性值为"noindex": 文件不检索,但可被查询链接;
  属性值为"nofollow": 文件不被检索,但可查询页上的链接。

 

限制复制,选择等..
<BODY οnmοuseup=document.selection.empty() οncοntextmenu="return false"
onselectstart="return false" οndragstart="return false"
onbeforecopy="return false" οncοpy=document.selection.empty() leftMargin=0
topMargin=0 οnselect=document.selection.empty()>

常用javascript语句集

下面列出些常用的javascript,大家可以把这些做成一个类,方便在项目中重复的调用。


1.让文字不停地滚动

  <MARQUEE>滚动文字</MARQUEE>

2.记录并显示网页的最后修改时间

  <script language=javascript>
  document.write("最后更新时间: " + document.lastModified + "")
  </script>

3.关闭当前窗口

  <a href="/"onClick="javascript:window.close();return false;">关闭窗口</a>

4.5秒后关闭当前页

  <script language="javascript">
  <!--
  setTimeout('window.close();',5000);
  -->
  </script>

5.2秒后载入指定网页

  <head>
  <meta http-equiv="refresh" content="2;URL=http://你的网址">
  </head>

6.添加到收藏夹

  <Script Language="javascript">
  function bookmarkit()
  {
  window.external.addFavorite('http://你的网址','你的网站名称')
  }
  if (document.all)document.write('<a href="#" onClick="bookmarkit()">加入收藏夹</a>')
  </Script>

7.让超链接不显示下划线

  <style type="text/css">
  <!-
  a:link{text-decoration:none}
  a:hover{text-decoration:none}
  a:visited{text-decoration:none}
  ->
  </style>

8.让网页随意后退

       <a href="javascript :history.go(-X)">X</a>

          //把X换成你想要后退在页数
   //把“-”变成“+”就为前进

9.设置该页为首页

  <body bgcolor="#FFFFFF" text="#000000">
  <!-- 网址:http://你的网址-->
  <a class="chlnk" style="cursor:hand" HREF
  onClick="this.style.behavior='url(#default#homepage)';
  this.setHomePage('你的网站名称);"><font color="000000" size="2" face="宋体">设为首页</font></a>
  </body>

10.节日倒计时

  <Script Language="javascript">
  var timedate= new Date("December 25,2003");
  var times="圣诞节";
  var now = new Date();
  var date = timedate.getTime() - now.getTime();
  var time = Math.floor(date / (1000 * 60 * 60 * 24));
  if (time >= 0)
  document.write("现在离"+times+"还有: "+time +"天")</Script>

11.单击按钮打印出当前页

  <Script Language="javascript">
  <!-- Begin
  if (window.print) {
  document.write('<form>'
  + '<input type=button name=print value="打印本页" '
  + 'onClick="javascript:window.print()"></form>');
  }
  // End -->
  </Script>

12.单击按钮‘另存为’当前页

  <input type="button" name="Button" value="保存本页"
  onClick="document.all.button.ExecWB(4,1)">
  <object id="button"
  width=0
  height=0
  classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
  <embed width="0" height="0"></embed>
  </object>

13.显示系统当前日期

  <script language=javascript>
  today=new Date();
  function date(){
  this.length=date.arguments.length
  for(var i=0;i<this.length;i++)
  this[i+1]=date.arguments }
  var d=new date("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
  document.write(
  "<font color=##000000 style='font-size:9pt;font-family: 宋体'> ",
  today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日",
  d[today.getDay()+1],"</font>" );
  </script>

14.不同时间段显示不同问候语

  <Script Language="javascript">
  <!--
  var text=""; day = new Date( ); time = day.getHours( );
  if (( time>=0) && (time < 7 ))
    text="夜猫子,要注意身体哦! "
  if (( time >= 7 ) && (time < 12))
    text="今天天气……哈哈哈,不去玩吗?"
  if (( time >= 12) && (time < 14))
    text="午休时间哦,朋友一定是不习惯午睡的吧?!"
  if (( time >=14) && (time < 18))
    text="下午茶的时间到了,休息一下吧! "
  if ((time >= 18) && (time <= 22))
    text="您又来了,可别和MM聊太久哦!"
  if ((time >= 22) && (time < 24))
    text="很晚了哦,注意休息呀!"
  document.write(text)
  //--->
  </Script>

15.水中倒影效果

  <img id="reflect" src="你自己的图片文件名" width="175" height="59">
  <script language="javascript">
  function f1()
  {
    setInterval("mdiv.filters.wave.phase+=10",100);
  }
  if (document.all)
  {
    document.write('<img id=mdiv src="'+document.all.reflect.src+'"
    style="filter:wave(strength=3,freq=3,phase=0,lightstrength=30) blur() flipv()">')
    window.οnlοad=f1
  }
  </script>

16.慢慢变大的窗口

  <Script Language="javascript">
  <!--
  var Windowsheight=100
  var Windowswidth=100
  var numx=5
  function openwindow(thelocation){
  temploc=thelocation
  if
  (!(window.resizeTo&&document.all)&&!(window.resizeTo&&document.getElementById))
  {
    window.open(thelocation)
    return
  }
  windowsize=window.open("","","scrollbars")
  windowsize.moveTo(0,0)
  windowsize.resizeTo(100,100)
  tenumxt()
  }
  function tenumxt(){
  if (Windowsheight>=screen.availHeight-3)
    numx=0
  windowsize.resizeBy(5,numx)
  Windowsheight+=5
  Windowswidth+=5
  if (Windowswidth>=screen.width-5)
  {
    windowsize.location=temploc
    Windowsheight=100
    Windowswidth=100
    numx=5
    return
  }
  setTimeout("tenumxt()",50)
  }
  //-->
  </script>
  <p><a href="javascript:openwindow(http://www.xxx.com)">进入</a>

17.改变IE地址栏的IE图标

  我们要先做一个16*16的icon(图标文件),保存为index.ico。把这个图标文件上传到根目录下并在首页<head></head>之间加上如下代码:
          <link REL = "Shortcut Icon" href="index.ico">

18.鼠标指向时弹出信息框
  <body>
  <a href οnmοuseοver="alert('弹出信息!')">显示的链接文字</a>
        </body>


19.单击鼠标右键弹出添加收藏夹对话框
  <body>
  <script Language=javascript>
  if (document.all)
  document.body.οnmοusedοwn=new function("if (event.button==2||event.button==3)
  window.external.addFavorite('您的网址','您的网站名称)")
  </script>
        </body>

20.离开网页时和加载网站时提示你将本站加入收藏夹

  可以很大的加大的网站的访问量。

  一、在网页的


  二、在网页中的  标记中加入下面的代码:

  οnunlοad=favorate()

  当然如果你想在网页载入时提示只需要把

  上面的οnunlοad=favorate()改成οnlοad=favorate()

21.JS制作网页标题栏滚动信息的显示:

将下面的代码copy到网页的<head>和</head>中.

<SCRIPT LANGUAGE=JAVASCRIPT>
<!--
var msg = "蓝色空间";
var speed = 300;
var msgud = " " + msg;
function titleScroll() {
if (msgud.length msgud = msgud.substring(1, msgud.length);
document.title = msgud.substring(0, msg.length);
window.setTimeout("titleScroll()", speed);
}
-->
</SCRIPT>

在网页的BODY中加入下面的代码:

<BODY οnlοad="window.setTimeout('titleScroll()', 500)">


22.JS状态栏信息分行显示:
 
将下面的代码copy到网页的<head>和</head>中.

<SCRIPT LANGUAGE=JAVASCRIPT>
<!--
function makeArray(n) {
this.length = n;
}
function stopBanner() {
if (bannerRunning)
clearTimeout(timerID);
bannerRunning = false;
}
function startBanner() {
stopBanner();
showBanner();
} function showBanner() {
var text = ar[currentMessage];
if (offset < text.length) {
if (text.charAt(offset) == " ")
offset++;
var partialMessage = text.substring(0, offset + 1);
window.status = partialMessage;
offset++;
timerID = setTimeout("showBanner()", speed);
bannerRunning = true;
} else {
offset = 0;
currentMessage++;
if (currentMessage == arlength)
currentMessage = 0;
timerID = setTimeout("showBanner()", pause);
bannerRunning = true;
}
}
var speed = 100
var pause = 1000
var timerID = null;
var bannerRunning = false;
var currentMessage = 0;
var offset = 0;
var arlength = 3;
var ar = new makeArray(arlength);
ar[0] = "蓝色空间";
ar[1] = "欢迎你的光临";
ar[2] = "有建议请联系V-蓝动力";
-->
</SCRIPT>

在网页的BODY中加入下面的代码:

<BODY οnlοad=startBanner()>

23. 可以在收藏夹中显示出你的图标

      <link rel="Bookmark" href="favicon.ico">

24. 永远都会带着框架

<script language="javascript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
// --></script>

25. 最小化、最大化、关闭窗口

<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize"></object>
<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Maximize"></object>
<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAM NAME="Command" value="Close"></OBJECT>

<input type=button value=最小化 οnclick=hh1.Click()>
<input type=button value=最大化 οnclick=hh2.Click()>
<input type=button value=关闭 οnclick=hh3.Click()>
本例适用于IE

26. TEXTAREA自适应文字行数的多少


<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">
</textarea>


27. 检测某个网站的链接速度:


把如下代码加入<body>区域中:
<script language=javascript>
tim=1
setInterval("tim++",100)
b=1

var autourl=new Array()
autourl[1]="www.njcatv.net"
autourl[2]="javacool.3322.net"
autourl[3]="www.sina.com.cn"
autourl[4]="www.nuaa.edu.cn"
autourl[5]="www.cctv.com"

function butt(){
document.write("<form name=autof>")
for(var i=1;i<autourl.length;i++)
document.write("<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GO οnclick=window.open(this.form.url"+i+".value)><br/>")
document.write("<input type=submit value=刷新></form>")
}
butt()
function auto(url){
document.forms[0]["url"+b].value=url
if(tim>200)
{document.forms[0]["txt"+b].value="链接超时"}
else
{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}
b++
}
function run(){for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl[i]+"/"+Math.random()+" width=1 height=1 οnerrοr=auto(http://";;+autourl[i]+"')>")}
run()</script>


28. 如何改变链接的鼠标形状

只需在链接上加上这一代码就行的了
或者跟上面的用CSS写也行

style="cursor:hand"       style="cursor:crosshair"
style="cursor:text"       style="cursor:wait"
style="cursor:move"       style="cursor:help"
style="cursor:e-resize"     style="cursor:n-resize"
style="cursor:nw-resize"     style="cursor:w-resize"
style="cursor:s-resize"     style="cursor:se-resize"
style="cursor:sw-resize"
以上代码你只需要加到连接或是页面的STYLE区里就可以实现鼠标多样化。

29.COOKIE脚本记录,有很大的用处。

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (documents.cookie.length > 0) {
offset = documents.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = documents.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = documents.cookie.length;
returnvalue=unescape(documents.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadpopup(){
if (get_cookie('popped')==''){
openpopup()
documents.cookie="popped=yes" 


}
}
说明:以上是JS代码,请自己加起始符和结束符

 


---------------  输出和后退

<script language="javascript">
alert("错误~~ 请输入帐号!!");
location.href="javascript:history.back()"
</script>

 

 

--------------- 输出并重定向

<script language="javascript">
alert("添加成功~~!!");
location.href="BookList.asp"
</script>

 

 

---------------- 内嵌一个页面并设置为可编辑

<script language="javascript">
     document.write ('<iframe src="text.asp" id="message" width="550" height="250"></iframe>')
      frames.message.document.designMode = "On";
</script>

 

 

--------------- 检验复选框是否已选并提示

<script language="javascript">
function checkdata()
{
if (document.form1.viewhtml.checked == true)
{
   alert("对不起,请取消“查看HTML源代码”后再添加!")
   document.form1.viewhtml.focus()
   return false
  }
}
</script>

 

 

---------------- 用JavaScript 在超连接中打开一个新窗口(可控制大小)

<a href=# onClick="javascript:window.open('Buy.asp?id=<% = rs("Id") %>','','width=570,height=160,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes');return false;">打开一个窗口</a>

 


一个自动更新的日历代码
<!-- Blog日历表开始 -->
<script language="javascript">
var diarydays="<2004-08-04><2004-08-03><2004-08-02><2004-08-01><2004-07-31><2004-07-30><2004-07-29><2004-07-27><2004-07-26><2004-07-25><2004-07-22><2004-07-21><2004-07-20><2004-07-19><2004-07-18><2004-07-16><2004-07-15><2004-07-14><2004-07-13><2004-07-12><2004-07-11><2004-07-10><2004-07-09><2004-07-08><2004-07-06><2004-07-05><2004-07-04><2004-07-03><2004-07-02><2004-07-01><2004-06-30><2004-06-27><2004-06-26>";
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.calendarBigBorder { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; text-decoration: none; width: 170; background-color: #FFFFFF; font-size: 9pt;border:1px dotted #999; }
.calendarTd { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; font-size: 9pt; color: #000000; background-color: #eeeeee; height: 18px; width: 11%; text-align: center;}
.calendarMInput { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; font-size: 9pt; text-decoration: none; background-color: #FFFFFF; height: 15px; border: 1px solid #666666; width: 19px; color: #0099FF;}
.calendarYInput { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; font-size: 9pt; color: #0099FF; text-decoration: none; background-color: #FFFFFF; height: 15px; width: 34px; border: 1px solid #666666;}
.calendarMonthTitle { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; font-size: 9pt; font-weight: normal; height: 24px; text-align: center; color: #333333; text-decoration: none; background-color: #eeeeee; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-bottom-style: none; border-top-color: #999999; border-right-color: #999999; border-bottom-color: #999999; border-left-color: #999999;}
.calendarNow { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; font-size: 9pt; font-weight: bold; color: #000000; background-color: #C0C9D3; height: 18px; text-align: center;}
.calendarDaySat { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; font-size: 9pt; color: #333333; text-decoration: none; background-color: #eeeeee; text-align: center; height: 18px; width: 12%;}
.calendarDaySun { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; font-size: 9pt; color: #333333; text-decoration: none; background-color: #eeeeee; text-align: center; height: 18px; width: 12%;}
.calendarLink { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; font-size: 9pt; font-weight: normal; color: #333333; text-decoration: none; background-color: #E7E7F6; text-align: center; height: 18px;}
.categoryTxt { font-family: "Arial", "Helvetica", "sans-serif", "宋体"; font-size: 9pt; line-height: 23px; color: #333333; text-decoration: none;}
.categoryTable { border-right-width: 1px; border-bottom-width: 1px; border-right-style: solid; border-bottom-style: solid; border-left-style: none; border-right-color: #000000; border-bottom-color: #000000; border-top-width: 1px; border-top-style: solid; border-top-color: #71b99c;}
</style>
<SCRIPT LANGUAGE="JavaScript">
var months = new Array("一", "二", "三","四", "五", "六", "七", "八", "九","十", "十一", "十二");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);
var days = new Array("日","一", "二", "三","四", "五", "六");
var classTemp;
var calendarHover="calendarHover";
var today=new getToday();
var year=today.year;
var month=today.month;
var newCal;
//得到某月天数
function getDays(month, year)
{ if (1 == month)
     return ((0 == year % 4) && (0 != (year % 100))) ||(0 == year % 400) ? 29 : 28;
  else
     return daysInMonth ;
}
//得到当天时间信息
function getToday()
{  this.now = new Date();
   this.year = this.now.getFullYear();
   this.month = this.now.getMonth();
   this.day = this.now.getDate();
}

//生成日历
function Calendar()
{  newCal = new Date(year,month,1); //当前月的第一天
   today = new getToday();  
   var day = -1;   //用来判断日历中是否为当天
   var startDay = newCal.getDay(); //当月开始时间
   var endDay=getDays(newCal.getMonth(), newCal.getFullYear());//当月结束时间
   var daily = 0;   //用来生成日历中的天数值
   if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth()))
      day = today.day;
   var caltable = document.all.caltable.tBodies.calendar;  //得到日历表格的集合
   var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear()); //得到当月天数
   //生成日历
   for (var intWeek = 0; intWeek < caltable.rows.length;intWeek++)
     for (var intDay = 0;intDay < caltable.rows[intWeek].cells.length;intDay++)
     {
      var cell = caltable.rows[intWeek].cells[intDay];   //得到单元袼
   //生成字符串用于判断当天是否有日志
      var montemp=(newCal.getMonth()+1)<10?("0"+(newCal.getMonth()+1)):(newCal.getMonth()+1);        
      if ((intDay == startDay) && (0 == daily)){ daily = 1;}
      var daytemp=daily<10?("0"+daily):(daily);
      var d="<"+newCal.getFullYear()+"-"+montemp+"-"+daytemp+">";
   //选择样式
      if(day==daily)
      cell.className="calendarNow";
      else if(diarydays.indexOf(d)!=-1)
         cell.className="calendarLink";
      else if(intDay==6)
      cell.className = "calendarDaySat";
      else if (intDay==0)
      cell.className ="calendarDaySun";
      else
      cell.className="calendarTd";
   //生成值
      if ((daily > 0) && (daily <= intDaysInMonth)) 
      {  cell.innerText = daily;
         daily++;
      }
      else
        cell.innerText = "";
    }
  document.all.year.value=year;
  document.all.month.value=month+1;
}

function subMonth()
{
  if ((month-1)<0)
  {
     month=11;
  year=year-1;
  }
  else
  {
    month=month-1;
  }
  Calendar();
}
function addMonth()
{
  if((month+1)>11)
  {
    month=0;
    year=year+1;
  }
  else
  {
    month=month+1;
  }
  Calendar();
}
//得到响应事件
function getDiary()
{
  var mon=(newCal.getMonth()+1)<10?("0"+(newCal.getMonth()+1)):(newCal.getMonth()+1);
  var day=event.srcElement.innerText<10?("0"+event.srcElement.innerText):(event.srcElement.innerText);
  var d="<"+newCal.getFullYear()+"-"+mon+"-"+day+">";
  if ("TD" == event.srcElement.tagName)
  if (("" != event.srcElement.innerText)&&(diarydays.indexOf(d)!=-1))
  {
   diary.location="/KanJing/archive/"+newCal.getFullYear()+"/"+mon+"/"+day+".aspx";
   window.location.href = diary.location;
  }
}

function setDate()
{
  if (document.all.month.value<1||document.all.month.value>12)
  {
    alert("月的有效范围在1-12之间!");
return;
  }
  year=Math.ceil(document.all.year.value);
  month=Math.ceil(document.all.month.value-1);
  Calendar();
}
</SCRIPT>
<table border="0" cellpadding="0" cellspacing="1" class="calendarBigBorder" id="caltable" width="200">
<thead>
     <tr align="center" valign="middle">
    <td colspan="7" class="calendarMonthTitle">
   <input name="year" type="text" class="calendarYInput" size="3" maxlength="4" οnkeydοwn="if (event.keyCode==13){setDate()}" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')"  οnpaste="this.value=this.value.replace(/[^0-9]/g,'')">年
   <input name="month" type="text" class="calendarMInput" size="1" maxlength="2" οnkeydοwn="if (event.keyCode==13){setDate()}" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')"  οnpaste="this.value=this.value.replace(/[^0-9]/g,'')">月 [<a onClick="addMonth()" href="javascript:;">下月</a>] [<a  onClick="subMonth()" href="javascript:;">上月</a>]</td>
  </tr>
<tr align="center" valign="middle">
<SCRIPT LANGUAGE="JavaScript"> 
document.write("<TD class=calendarDaySun id=diary>" + days[0] + "</TD>");
for (var intLoop = 1; intLoop < days.length-1;
intLoop++)
document.write("<TD class=calendarTd id=diary>" + days[intLoop] + "</TD>");
document.write("<TD class=calendarDaySat id=diary>" + days[intLoop] + "</TD>");
</SCRIPT>
</TR>
</thead>
  <TBODY border=1 cellspacing="0" cellpadding="0" ID="calendar" ALIGN=CENTER ONCLICK="getDiary()" οnmοuseup=document.selection.empty() οncοntextmenu="return false" onselectstart="return false" οndragstart="return false" onbeforecopy="return false" οncοpy=document.selection.empty() οnselect=document.selection.empty()>
    <SCRIPT LANGUAGE="JavaScript">
  for (var intWeeks = 0; intWeeks < 6; intWeeks++) {
  document.write("<TR style='cursor:hand'>");
  for (var intDays = 0; intDays < days.length;intDays++)
  document.write("<TD class=calendarTd onMouseover='{classTemp=this.className;this.className=calendarHover}' onMouseOut='this.className=classTemp'></TD>");
  document.write("</TR>");
  }
</SCRIPT>
  </tbody>
</table>
<script  LANGUAGE="JavaScript">
Calendar();
</script>
<!-- Blog日历表结束 -->

 


关键字:两级联动菜单
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="JavaScript" type="text/javascript">
<!--
var province_ar=new Array("","学历文凭|旅游管理,工商企业管理,文秘,金融,国际贸易,会计,英语,计算机应用,法律,艺术设计","成人高教|工商企业管理,国际经济与贸易,外贸英语,计算机应用与管理,艺术设计","高教自考|饭店管理,工商企业管理,中英合作商务管理,保险,国际贸易,英语,电子商务,计算机及应用,法律,广告");

function show_province()
{
var pro_tmp=document.all.province;
for (m=pro_tmp.options.length-1;m>0;m--)
pro_tmp.options[m]=null;

for(i=0;i<province_ar.length;i++)
{
if(province_ar[i]!="")
{
tmp=province_ar[i].split("|");
pro_tmp.options[i]=new Option(tmp[0],tmp[0]);
}
}
}
function show_city(sc)
{
var temp=document.all.city;
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null;

if(province_ar[sc]!="")
{
tmp=province_ar[sc].split("|");
tmp=tmp[1];
tmp=tmp.split(",");
for(i=0;i<tmp.length;i++)
{
temp.options[i]=new Option(tmp[i],tmp[i]);
}
}
}
setTimeout("show_province();",20);//第一个搜索中省份城市对应
-->
</script>
</HEAD>

<BODY>
<FORM name="testform" id="testform">
<select id=province 
     οnchange=show_city(this.options.selectedIndex)>
<OPTION value="" selected>请选择类别</option>
</select>
<select id=city>
   <OPTION value="" selected>请选择专业</OPTION>
</select>
</FORM>
</BODY>
</HTML>

----------------------------------------------------------------------------------------------

 

多级联动菜单

----------------------------------------------------------------------------------------------


<BODY>
<Select NAME="s1"><option>需要JavaScript才能正确显示</Select>
<Select NAME="s2">
</Select>
<Select NAME="s3"></Select>
<Select NAME="s4"></Select>
<SCRIPT LANGUAGE="JavaScript">
<!--
//选择框的名字
selector = [ "s1", "s2", "s3", "s4" ];
//选择项: "名字", "值", 子选择
menu = [
"地球","1",
[
"中国","86",
[
"北京","BJ",
  [
  "--","1",null
  ],
"四川","SC",
  [
  "成都","28",null,
  "乐山","",null,
  "攀枝花","",null,
  "自贡","",null,
  "德阳","",null,
  "绵阳","",null
  ]
],
"米国","1",
[
"加利福尼亚","CA",
  [
  "旧金山","1",null,
  "洛杉矶","2",null
  ],
"华盛顿","WA",
  [
  "西雅图","seattle",null
  ]
]
],
"火星","2",
[
"大峡谷","86",
[
"小山丘","BJ",
  [
  "A地区","28",null,
  "B地区","",null,
  "C地区","",null
  ]
]
]
];

function wizz(level)
{
if( level == 0 )
a = menu;
else
{
str = "menu";
for( i=0; i<level; i++ )
  str += "[" + (document.all[selector[i]].selectedIndex * 3 + 2)  + "]";
a = eval(str);
}
if( a == null ) return;
s = document.all[selector[level]];
i = s.length;
while( i > 0 ) s.options[--i] = null;
while( i < Math.floor(a.length/3) )
s.options[i] = Option( a[i*3], a[i++*3+1] );
s.onchange = Function("wizz(" + (level+1) + ")");
wizz(level+1);
}
wizz(0);
//-->
</SCRIPT>
</BODY>
</HTML>

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值