zoukankan      html  css  js  c++  java
  • 常用的JavaScript代码

     
    (1).在打开的子窗口刷新父窗口的代码里如何写?
    window.opener.location.reload()
    (2).如何设定打开页面的大小
    <body onload="top.resizeTo(300,200);">
    打开页面的位置<body onload="top.moveBy(300,200);">
    (3).在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动
    <STYLE>
    body
    {
    background-image:url(/logo.gif); background-repeat:no-repeat;
    background-position:center;background-attachment: fixed
    }
    </STYLE>
    (4). 检查一段字符串是否全由数字组成
    <script language="Javascript">
    function checkNum(str)
    {
    return str.match(//D/)==null
    }
    alert(checkNum("1232142141"))
    alert(checkNum("123214214a1"))
    </script>
    (5). 获得一个窗口的大小
    document.body.clientWidth;
    document.body.clientHeight
    (6). 怎么判断是否是字符
    if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");
    else alert("全是字符");
    (7).TEXTAREA自适应文字行数的多少
    <textarea rows=1 name=s1 cols=27 onpropertychange
    ="this.style.posHeight=this.scrollHeight">
    </textarea>
    (7).脚本永不出错
    <SCRIPT LANGUAGE="JavaScript">
    function killErrors()
    {
    return true;
    }
    window.onerror = killErrors;
    </SCRIPT>
    (8).ENTER键可以让光标移到下一个输入框
    <input onkeydown="if(event.keyCode==13)event.keyCode=9">
    (9).页面进入和退出的特效
    进入页面<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.竖条 以上22种随机选择一种
    (10)、JavaScript主页弹出窗口技巧
    窗口中间弹出
    <script>
    window.open("http://www.cctv.com","","width=400,height=240,top="+(screen.availHeight-240)/2+",left="+(screen.availWidth-400)/2);
    </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>

    父窗口代码

    <a href="#" onclick="window.open('child.html','child','width=400,height=300,left=200,top=200');">打开子窗口</a>

    子窗口代码

    <script language="JavaScript" type="text/javascript"> <!-- function refreshParent() { window.opener.location.href = window.opener.location.href; if (window.opener.progressWindow) { window.opener.progressWindow.close(); } window.close(); }

     
    <body>
    <img src="2.jpg"><br>
    <input type=button value="放大" onclick="large()">
    <input type=button value="缩小" onclick="small()">
    <input type=button value="旋转" onclick="rotate()">
    <input type=button value="打印" onclick="printPic()">
    </body>
    <script>
    var img=document.getElementsByTagName('img')[0];
    function small()
    {
    img.width=img.width*0.5;
    img.height=img.height*0.5;
    }
    function large()
    {
    img.width=img.width*2;
    img.height=img.height*2;
    }
    function rotate()
    {
    //rotation: 1 旋转90度 ;2 旋转180度 ;3 旋转270度
    img.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation=1)'
    }
    function printPic()
    {
    window.print();
    }
    </script>
  • 相关阅读:
    -bash: fork: Cannot allocate memory 问题的处理
    Docker top 命令
    docker常见问题修复方法
    The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
    What's the difference between encoding and charset?
    hexcode of é î Latin-1 Supplement
    炉石Advanced rulebook
    炉石bug反馈
    Sidecar pattern
    SQL JOIN
  • 原文地址:https://www.cnblogs.com/benzhang/p/1743120.html
Copyright © 2011-2022 走看看