【学习笔记】javascript 基础篇 变量 运算符 函数

var nob00 = 10;//动态变量,不用声明类型,PHP一样

var str00 = 'I have a dream';//这是一个String对象,一切皆对象

var strlen = str00.length;//调用属性

var strup = str00.toUpperCase();//调用方法

var day = new Date().getDay();//星期

var arr00 = new Array('Sunday','Tuesday','Wednesday','Thursday','Friday','Saturday');

var arr01 = [23,32,66,54,56,89];

function altTest(){
    alert('Hello JS');
}

function reWriteH1(){  
    
    newStr =document.getElementById('input00').value;//第一次使用不声明var自动全局
    document.getElementById('h1').innerHTML = newStr;
    //alert(str00);//局域内可以调用全局 PHP不能直接调用
}

if(strlen>10){
    
    document.write('str00 length = '+strlen+'<br>');//+连接,PHP是.
}else if(strlen<8){//PHP是elseif
    document.write('str00 length = '+strlen+'<br>');
}else{
    document.write('str00 length = '+strlen+'<br>');
}

switch(day){
    case 0:
        document.write('Today is '+arr00[0]+'<br>');
        break;
    case 1:
        document.write('Today is '+arr00[1]+'<br>');
        break;
    case 2:
        document.write('Today is '+arr00[2]+'<br>');
        break;
    case 3:
        document.write('Today is '+arr00[3]+'<br>');
        break;
    case 4:
        document.write('Today is '+arr00[4]+'<br>');
        break;
    case 5:
        document.write('Today is '+arr00[5]+'<br>');
        break;
    case 6:
        document.write('Today is '+arr00[6]+'<br>');
        break;
    default:
        document.write('Something Error'+'<br>');
              
}

for(var i = 0,l = arr01.length;i<l;i++){// 初始化l节省cpu
    document.write(arr01[i]+',')
    var j = i;
}
document.write('<br/>');

document.write('var i in for() = '+i+'<br/>');//6 全局

document.write('var j in for{} = '+j+'<br/>');//5 全局

try{
    //for(tmp in arr00){//有问题
       //    var txt +=tmp;
    //}
    
    document.write('var tmp in forin() = '+tmp+'<br/>');

    document.write('var txt in forin{} = '+txt+'<br/>');
}catch(err){
    document.write('fun run error: '+err.message+'<br/>');
}    


document.write('<hr/>');

for in 出问题了,js本身不难得感觉,要和HTML CSS XML DOM 。。。搭配好不是容易的事情!

posted @ 2015-11-15 23:21  逢妹必问约  阅读(228)  评论(0编辑  收藏  举报