JavaScript学习
javascript 改变HTML样式:
<script>
function test(){
x=document.getElementById("div");
x.style.color="red";//改变html的样式
}
</script>
Hello,world
点击前:
点击后
javascript 验证,关键词:isNaN 判断是不是一个数
<script>
function test(){
alert(isNaN("3"));
alert(isNaN(3));
}
</script>
运行后:
javascript改变字体样式:
<script>
function test(){
var z = document.getElementById("p");
z.align = "right";
z.style.color = "red";
z.style.fontSize = "100px";
var c = document.getElementById("div");
c.align = "right";
c.style.color = "red";
c.style.fontSize = "100px";
}
}
</script>
你好
您好
javascript运算:
<script>
function test(){
var x ;
x = 3;
y = 2;
x = x + y;
alert(x);
alert(y);
}
</script>
<script>
function test(){
var x,y,z;
x =1;
y =2;
z = x+y;
alert(z);
}
</script>
函数传参:
<script>
function test1(x,y){
return x+y;
}
function test(x,y){
alert(x,y);
}
</script>
js中运算符:
= :赋值,
==:等于
===:值一样,类型也一样
js数组
<script>
function test(){
var shuzu = new Array;
shuzu[0] = "asd";
shuzu[1] = "fddsdfsdfs";
shuzu[2] = "asdsdffd";
for(var i = 0; i
js字符串转数字:
<script>
function test(){
var x = "1";
var y = 1;
alert(parseInt(x)+y);
</script>
获取时间:
<script>
function test(){
var date = new Date();
alert(date);
alert(date.getTime());
alert(date.toUTCString());
alert(date.getDay());
alert(date.getHours() + "时");
alert(date.getMinutes() + "分" );
alert(date.getSeconds() + "秒");
alert(date.getMilliseconds() + "毫秒");
}
</script>