javascript
判断一个变量是哪种类型
变量 instanceof Array
字符串处理方式
var text= 'name=1;username=hello;asus1=38code' ;
var text_split= text. split ( ';' ) ;
var pp= '' ;
for ( var i= 0 ; i< text_split. length; i++ ) {
var c= text_split[ i] . trim ( ) ;
pp+= c. indexOf ( 'name=' ) + ' ' ;
}
's12345ytf' . substring ( 2 , 4 ) ;
cookie使用
document. cookie= username+ '=' + name;
document. cookie
使用开始按钮和停止按钮计时
< ! DOCTYPE html>
< html>
< head>
< meta charset= 'utf-8' / >
< / head>
< body>
< form>
< input type= "button" value= "start" onclick= "start()" / >
< input type= "text" id= "txt" / >
< input type= 'button' value= 'over' onclick= 'over()' / >
< / form>
< script>
var text= document. getElementById ( 'txt' ) ;
var number= 0 ;
var on_off= false ;
var clock= undefined;
function count_time ( ) {
text. value= number;
number+= 1 ;
clock= setTimeout ( 'count_time()' , 1000 ) ;
}
function start ( ) {
if ( on_off== false ) {
on_off= true ;
count_time ( ) ;
}
}
function over ( ) {
if ( on_off== true ) {
on_off= false ;
clearTimeout ( clock) ;
}
}
< / script>
< / body>
< / html>
数字时钟
< ! DOCTYPE html>
< html>
< head>
< meta charset= 'utf-8' / >
< script>
function check_time ( date) {
if ( date< 10 )
return '0' + date;
else
return date;
}
function clock ( ) {
var today= new Date ( ) ;
var h= check_time ( today. getHours ( ) ) ;
var m= check_time ( today. getMinutes ( ) ) ;
var s= check_time ( today. getSeconds ( ) ) ;
document. getElementById ( 'show' ) . innerHTML= h+ ':' + m+ ':' + s;
setTimeout ( 'clock()' , 800 ) ;
}
< / script>
< / head>
< body onload= 'clock()' >
< div id= 'show' > < / div>
< / body>
< / html>
js中如何隐藏样式
变量. style. display= "none" :“none”是一个值,表示元素将隐藏。
以某一周期调用函数
var id = setInterval ( frame, 100 ) ;
function frame ( ) {
if ( width >= 100 ) {
clearInterval ( id) ;
} else {
width++ ;
pan. innerHTML= width;
elem. style. width = width + '%' ;
}
}
事件监听
document. getElementById ( "clear" ) . addEventListener ( "click" , function ( ) {
document. getElementById ( "display" ) . value = "" ;
} ) ;
eval函数进行数字运算
参考:https: / / www. cnblogs. com/ firstlady/ p/ 11347382. html
eval ( ) 可以接受一个字符串str作为参数,并把这个参数作为脚本代码来执行。
如:eval ( "2+3" ) ;