zoukankan      html  css  js  c++  java
  • JS函数大全

    onkeypress 事件

    定义和用法

    onkeypress 事件会在键盘按键被按下并释放一个键时发生。

    语法:

    onkeypress="SomeJavaScriptCode"

    提示和注释

    浏览器差异:Internet Explorer 使用 event.keyCode 取回被按下的字符,而 Netscape/Firefox/Opera 使用 event.which。

    实例

    在本例中,用户无法在输入框中键入数字:

    <html>
    <body>
    <script type="text/javascript">
    function noNumbers(e)
    {
    var keynum
    var keychar
    var numcheck
    
    if(window.event) // IE
      {
      keynum = e.keyCode
      }
    else if(e.which) // Netscape/Firefox/Opera
      {
      keynum = e.which
      }
    keychar = String.fromCharCode(keynum)
    numcheck = /\d/
    return !numcheck.test(keychar)
    }
    </script>
    
    <form>
    <input type="text" onkeypress="return noNumbers(event)" />
    </form>
    
    </html>

    JavaScript fromCharCode() 方法

    定义和用法

    fromCharCode() 可接受一个指定的 Unicode 值,然后返回一个字符串。

    实例

    在本例中,我们将根据 Unicode 来输出 "HELLO" 和 "ABC":

    <script type="text/javascript">
    
    document.write(String.fromCharCode(72,69,76,76,79))
    document.write("<br />")
    document.write(String.fromCharCode(65,66,67))
    
    </script>

    以上代码的输出:

    HELLO
    ABC

  • 相关阅读:
    python3之面向对象实例存家具
    python3之面向对象实例烤地瓜
    python3之批量修改文件名称
    python3处理大文件
    利用函数的递归计算数字的阶乘
    windows10安装.netframework3.5
    centos7-django(python3)环境搭建
    centos7-django(python3)环境搭建!
    Java线程池
    python设置编码
  • 原文地址:https://www.cnblogs.com/laonanren/p/2917370.html
Copyright © 2011-2022 走看看