zoukankan      html  css  js  c++  java
  • js typeof

    typeof 语法中的圆括号是可选项。

    经常会在js里用到数组,比如 多个名字相同的input, 若是动态生成的, 提交时就需要判断其是否是数组.

    if(document.mylist.length != "undefined" ) {} 这个用法有误.

    正确的是 if( typeof(document.mylist.length) != "undefined" ) {}

    或 if( !isNaN(document.mylist.length) ) {}

    typeof的运算数未定义,返回的就是 "undefined".

    运算数为数字 typeof(x) = "number"

    字符串 typeof(x) = "string"

    布尔值 typeof(x) = "boolean"

    对象,数组和null typeof(x) = "object"

    函数 typeof(x) = "function"

    typeof 运算符返回一个用来表示表达式的数据类型的字符串。 可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。 如: alert(typeof (123));//typeof(123)返回"number" alert(typeof ("123"));//typeof("123")返回"string"

     另一种:

    <body>
    <h1>ddd</h1>
    <p>ffff</p>
    <ul id="test">
    <li>aa</li>
    <li>aas</li>
    <li>aad</li>
    </ul>
    <script type=>
    alert(typeof document.getElementById("test"));//此处typeof省略了圆括号
    </script>
    </body>

  • 相关阅读:
    oracle中的游标
    Oracle中的表空间
    Oracle中建表及表操作
    oracle中的权限管理
    oracle中的数据类型
    Oracle中常用的系统函数
    oracle中的dual表简介
    Oracle中常用的系统表
    Git常用命令总结
    Git配置文件与git config命令
  • 原文地址:https://www.cnblogs.com/zhhq/p/3429807.html
Copyright © 2011-2022 走看看