网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 Javascript常用技巧20个
内容
    1.如何设定打开页面的大小 <body onload="top.resizeTo(300,200);">
    打开页面的位置<body>
    2.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动 <STYLE>
    body
    {background-image:url(/logo.gif); background-repeat:no-repeat;
    background-position:center;background-attachment: fixed}
    </STYLE>
    3. 检查一段字符串是否全由数字组成 <script language="Javascript"><!--
    function checkNum(str){return str.match(//D/)==null}
    alert(checkNum("1232142141"))
    alert(checkNum("123214214a1"))
    // --></script>
    4. 获得一个窗口的大小 document.body.clientWidth; document.body.clientHeight
    5. 怎么判断是否是字符 if (/[^/x00-/xff]/g.test(s))
    alert("含有汉字");
    else
    alert("全是字符");
    6.TEXTAREA自适应文字行数的多少 <textarea rows=1 name=s1 cols=27 onpropertychange "this.style.posHeight=this.scrollHeight">
    </textarea>
    7. 日期减去天数等于第二个日期 <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>
    8. 选择了哪一个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="/blog/barcode">Barcode
    <INPUT type="button" value="check" onclick="checkme()">
    </BODY></HTML>
    9.脚本永不出错 <SCRIPT LANGUAGE="JavaScript">
    <!-- Hide
    function killErrors() {
    return true;
    }
    window.onerror = killErrors;
    // -->
    </SCRIPT>
    10.ENTER键可以让光标移到下一个输入框 <input onkeydown="if(event.keyCode==13)event.keyCode=9">
    11. 检测某个网站的链接速度:
    把如下代码加入<body>区域中: <script language=Javascript>
    tim=1
    setInterval("tim++",100)
    b=1
    var autourl=new Array()
    autourl[1]=1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>www.njcatv.net"
    autourl[2]="javacool.3322.net"
    autourl[3]=1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>www.sina.com.cn"
    autourl[4]=""
    autourl[5]=1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>www.cctv.com"
    function butt(){
    ***("<form name=autof>")
    for(var i=1;i<autourl.length;i++)
    ***("<input type=text name=txt"+i+" size=10 value="/测试中……> =》<input type=text
    name=url"+i+" size=40> =》<input type=button value="/blog/GO
    onclick=window.open(this.form.url"+i+".value)><br>")
    ***("<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="/blog/时间"+tim/10+"秒"}
    b++
    }
    function run(){for(var i=1;i<autourl.length;i++)***("<img src=http://"+autourl+"/"+Math.random()+" width=1 height=1
    onerror=auto("+"")>")}
    run()</script>
    12. 各种样式的光标
    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
    13.页面进入和退出的特效
    进入页面
    <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种随机选择一种
    14.在规定时间内跳转 <META http-equiv=V="REFRESH" content="5;URL=http://www.1212bb.com">
    15.网页是否被检索
    <meta name="ROBOTS" content="属性值">
    其中属性值有以下一些:
    属性值为"all": 文件将被检索,且页上链接可被查询;
    属性值为"none": 文件不被检索,而且不查询页上的链接;
    属性值为"index": 文件将被检索;
    属性值为"follow": 查询页上的链接;
    属性值为"noindex": 文件不检索,但可被查询链接;
    属性值为"nofollow": 文件不被检索,但可查询页上的链接。
    16、email地址的分割
    把如下代码加入<body>区域中 <a href=">
    17、流动边框效果的表格
    把如下代码加入<body>区域中 <SCRIPT>
    l=Array(6,7,8,9,'a','b','b','c','d','e','f')
    Nx=5;Ny=35
    t="<table border=0 cellspacing=0 cellpadding=0 height="+((Nx+2)*16)+"><tr>"
    for(x=Nx;x<Nx+Ny;x++)
    t+="<td width=16 id=a_mo"+x+"> </td>"
    t+="</tr><tr><td width=10 id=a_mo"+(Nx-1)+"> </td><td colspan="+(Ny-2)+" rowspan="+(Nx)+"> </td><td width=16 id=a_mo"+(Nx+Ny)+"></td></tr>"
    for(x=2;x<=Nx;x++)
    t+="<tr><td width=16 id=a_mo"+(Nx-x)+"> </td><td width=16 id=a_mo"+(Ny+Nx+x-1)+"> </td></tr>"
    t+="<tr>"
    for(x=Ny;x>0;x--)
    t+="<td width=16 id=a_mo"+(x+Nx*2+Ny-1)+"> </td>"
    ***(t+"</tr></table>")
    var N=Nx*2+Ny*2
    function f1(y){
    for(i=0;i<N;i++){
    c=(i+y)%20;if(c>10)c=20-c
    document.all["a_mo"+(i)].bgColor=""""#0000"+l[c]+l[c]+"'"}
    y++
    setTimeout('f1('+y+')','1')}
    f1(1)
    </SCRIPT>
    18、JavaScript主页弹出窗口技巧
    窗口中间弹出 <script>
    window.open(");
    </script>
    ============
    <html>
    <head>
    <script language="LiveScript">
    function WinOpen() {
    msg=open("","DisplayWindow","toolbar=no,directories=no,menubar=no");
    msg.***("<HEAD><TITLE>哈 罗!</TITLE></HEAD>");
    msg.***("<CENTER><H1>酷 毙 了!</H1><h2>这 是<B>JavaScript</B>所 开 的 视 窗!</h2></CENTER>");
    }
    </script>
    </head>
    <body>
    <form>
    <input type="button" name="Button1" value="Push me" onclick="WinOpen()">
    </form>
    </body>
    </html>
    ==============
    一、在下面的代码中,你只要单击打开一个窗口,即可链接到赛迪网。而当你想关闭时,只要单击一下即可关闭刚才打开的窗口。
    代码如下: <SCRIPT language="JavaScript">
    <!--
    function openclk() {
    another=open('1000){this.resized=true;this.style.width=1000;}" align=absMiddle border=0>http://www.ccidnet.com','NewWindow');
    }
    function closeclk() {
    another.close();
    }
    //-->
    </SCRIPT>
    <FORM>
    <INPUT TYPE="BUTTON" NAME="open" value="/打开一个窗口" onClick="openclk()">
    <BR>
    <INPUT TYPE="BUTTON" NAME="close" value="/blog/关闭这个窗口" onClick="closeclk()">
    </FORM>
    二、上面的代码也太静了,为何不来点动感呢?如果能给页面来个降落效果那该多好啊!
    代码如下: <script>
    function drop(n) {
    if(self.moveBy){
    self.moveBy (0,-900);
    for(i = n; i > 0; i--){
    self.moveBy(0,3);
    }
    for(j = 8; j > 0; j--){
    self.moveBy(0,j);
    self.moveBy(j,0);
    self.moveBy(0,-j);
    self.moveBy(-j,0);
    }
    }
    }
    </script>
    <body onLoad="drop(300)">
    三、讨厌很多网站总是按照默认窗口打开,如果你能随心所欲控制打开的窗口那该多好。
    代码如下: <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function popupPage(l, t, w, h) {
    var windowprops = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes" +
    ",left=" + l + ",top=" + t + ",width=" + w + ",height=" + h;
    var URL = "";
    popup = window.open(URL,"MenuPopup",windowprops);
    }
    // End -->
    </script>
    <table>
    <tr>
    <td>
    <form name=popupform>
    <pre>
    打开页面的参数<br>
    离开左边的距离: <input type=text name=left size=2 maxlength=4> pixels
    离开右边的距离: <input type=text name=top size=2 maxlength=4> pixels
    窗口的宽度: <input type=text name=width size=2 maxlength=4> pixels
    窗口的高度: <input type=text name=height size=2 maxlength=4> pixels
    </pre>
    <center>
    <input type=button value="打开这个窗口!" onClick="popupPage(this.form.left.value, this.form.top.value, this.form.width.value,
    this.form.height.value)">
    </center>
    </form>
    </td>
    </tr>
    </table>
    你只要在相对应的对话框中输入一个数值即可,将要打开的页面的窗口控制得很好。
    19、页面的打开移动
    把如下代码加入<body>区域中 <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    for (t = 2; t > 0; t--) {
    for (x = 20; x > 0; x--) {
    for (y = 10; y > 0; y--) {
    parent.moveBy(0,-x);
    }
    }
    for (x = 20; x > 0; x--) {
    for (y = 10; y > 0; y--) {
    parent.moveBy(0,x);
    }
    }
    for (x = 20; x > 0; x--) {
    for (y = 10; y > 0; y--) {
    parent.moveBy(x,0);
    }
    }
    for (x = 20; x > 0; x--) {
    for (y = 10; y > 0; y--) {
    parent.moveBy(-x,0);
    }
    }
    }
    //-->
    // End -->
    </script>
    20、显示个人客户端机器的日期和时间 <script language="LiveScript">
    <!-- Hiding
    today = new Date()
    ("现 在 时 间 是: ",today.getHours(),":",today.getMinutes())
    ("<br>今 天 日 期 为: ", today.getMonth()+1,"/",today.getDate(),"/",today.getYear());
    // end hiding contents -->
    </script>
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/16 3:13:02