js学习记录

js  数据类型

typeof "John"                 // 返回 string
typeof 3.14                   // 返回 number
typeof NaN                    // 返回 number                 isNaN(),判断是否为非数值
typeof false                  // 返回 boolean
typeof [1,2,3,4]              // 返回 object                    数组比较特殊,返回object类型
typeof {name:'John', age:34}  // 返回 object
typeof new Date()             // 返回 object
typeof function () {}         // 返回 function
typeof myCar                  // 返回 undefined (如果 myCar 没有声明)
typeof null                   // 返回 object              
undefined                      //undefined
 
constructor 属性返回所有 JavaScript 变量的构造函数。你可以使用 constructor 属性来查看对象是否为数组 (包含字符串 "Array"):
 
 
"John".constructor                 // 返回函数 String()  { [native code] }
(3.14).constructor                 // 返回函数 Number()  { [native code] }
false.constructor                  // 返回函数 Boolean() { [native code] }
[1,2,3,4].constructor              // 返回函数 Array()   { [native code] }
{name:'John', age:34}.constructor  // 返回函数 Object()  { [native code] }
new Date().constructor             // 返回函数 Date()    { [native code] }
function () {}.constructor         // 返回函数 Function(){ [native code] }
 
 
 
 
 
类型转换,
数组转换为数字。
Number("3.14")    // 返回 3.14
Number(" ")       // 返回 0
Number("")        // 返回 0
Number("99 88")   // 返回 NaN
 
转换为字符串
String(),    X.toString().
字符串转换为整数,parseInt("A")          parseFloat()
 
页面刷新 JS,使用setTimeout方法。
 function fun(){
                window.location.reload();
             }
             setTimeout('fun()',1000);   //每过1秒执行fun函数   
 
dom
document.getelementById().innerHTML=" "   改变内容。      document.getelementById().style.color="#F00"  改变CSS      document.getelementById().click=function();绑定方法
document.getelementsByTagName();
document.getElementsByClassName("intro"); 
 
 Jquery:
each:   遍历,绑定方法。
  $("li").each(function(){
                $(this).mouseover(function() {
                    this.style.color="#F00";
               });
 
 
 
原文地址:https://www.cnblogs.com/zl0717/p/7452094.html