首页 > Web开发 > 详细

JS基础

时间:2014-12-19 17:08:42      阅读:189      评论:0      收藏:0      [点我收藏+]

// statement (语句)
// variable (变量)
// assignment(赋值)
// declare(申明)
// typing(类型申明)

var a, b;

var a;
var b;

var a = 1;
var b = 2;

var a, b;
a = 1;
b = 2;

// array(数组)
// element(元素)

var beatles = array();//括号内为元素个数
// array[index] = element;
beatles[0] = "john";

var beatles = array("joho","ok");
var beatles = ["john","paul"];

var lenoon = []; //数组赋值给另一个数组的元素
lenoon[0] = beatles;

lenoon[0][1];

// Object(对象)
var beatles = Object();
beatles.name = "john"
beatles.year = "1994"

// 对象代替数组
var beatles = Object();
var beatles = { name:"john",year:"1992"};

var beatles = {}; // 数组声明为对象
beatles.vocalist = lenoon;

beatles.vocalist.name = "john";

// 算数操作符
var a = "ff";
var b = "hah" + a;

var year = 2010;
var message = "this year is";
message += + year;
alert(message);

// 条件语句
if (condition) {
statements;
};

if (1>2) {
alert("hello");
}else{
alert("fuck");
}

var a, b;
a = "a";
b = "alert";

if (a == b) {
alert("same");
}else{
alert("false");
}

// 逻辑操作符
var a = 4;
if (a >= 5 && a <= 10) {
alert("a");
}

// 循环语句
var count = 1;
while (count < 11){
alert(count);
count++;
}

var count = 1;
do {
alert(count);
count++;
}while(count < 1);

for (var count = 1; count < 3; count++ ) {
alert(count);
}

// 数组循环
var beatles = Array("a","b","c","d");
for (var count = 0; count < beatles.length; count++) {
alert(beatles[count]);
};

// 函数:多次调用的代码可以封装成为函数
function shout () {
var beatles = Array("a","b","c","d");
for (var count = 0; count < beatles.length; count++) {
alert(beatles[count]);
};
}

shout()// 调用

//函数给变量赋值
function c(temp) {
var resule = temp - 32;
resule = resule / 1.8;
return = resule;
}

var temp_1 = 95;
var temp_2 = c (temp_1);
alert(temp_2);

JS基础

原文:http://www.cnblogs.com/cailiqiang/p/4174258.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!