賦值運(yùn)算符
=
+=
-=
*=
%=
關(guān)系運(yùn)算符
var result =5>10; false
<
<=
var result =1>true; true和數(shù)字比較變 1 false
var result =1>‘0’; 1>0
var result =5>null; 5>0
var result =10>'hello'; 10 > nan 和nan比較永遠(yuǎn) false
var result =‘5’<‘10’; 二面都是字符串 比較字符串的unnicode 的編碼
var result =‘a(chǎn)b’<‘a(chǎn)’拿第一位比 第一位相等 繼續(xù)比第二位 誰大水就大。
用來對英文的排序。
scriper
unicode
console.log('\2685')
16進(jìn)制。
body
里面用十進(jìn)制
⚅
相等運(yùn)算符
==
console.log(‘1’=1) true ‘1’默認(rèn)轉(zhuǎn)為number
console.log(true=1) true
console.log(null==0) false
console.log(null == undfined) true null衍生過來的
console.log(nan='1') false nan不等于一切包括自己
var b=nan
console.log(b == nan) 無法判斷 b=nan
console.log(isnan(b)) true
console.log('1' != 1)false
console.log('1' === 1)false 類型不行直接否
console.log(null === undfined) false
console.log(‘1’!== 1) true 不全等
條件運(yùn)算符 三元運(yùn)算符 三木運(yùn)算符
條件表達(dá)式 ? 語句1 :語句2; true 1 false2
獲取a,b最大值
var max = a>b? a:b ; max放返回值
獲取a,b,c最大值
max = max>c? max:c ;
簡寫:
var max = a>b?(a>c?a:c):(b>c?b:c);
運(yùn)算符優(yōu)先級
,
&& > ||
代碼塊
{}
代碼塊包著的一起執(zhí)行了。分組了
title提示作用
document 作用于html標(biāo)簽里
document .getElementById(‘div1’).title ='我看到了';
因?yàn)樵赽ody最后加載,是因?yàn)閐iv都加載完畢以后使用。
整個(gè)文檔加載完畢以后執(zhí)行的匿名函數(shù) 可以放在上面的解決辦法。
window.onlond=function() 瀏覽器對象。bom對象。定時(shí)器,報(bào)警提示
var oA =document .getElementById(‘div1’)
寫入
oA . href='dsff'
oA .title='dsds'
讀取
alert(oA.id)
alert(oA.title)
js換膚
window.onlond=function() 瀏覽器對象。bom對象。定時(shí)器,報(bào)警提示
var oline =document .getElementById(‘div1’)
olink.herf='css/a.css'
js操作style屬性
window.onlond=function() 瀏覽器對象。bom對象。定時(shí)器,報(bào)警提示
var oDiv=document .getElementById(‘div1’)
oDiv.style.color = 'red'
body
<div id=;div1'> sdadsa輔導(dǎo)費(fèi)</div>
body
font-size不能用 改為fontSize就可以用。
js操作class
window.onlond=function() 瀏覽器對象。bom對象。定時(shí)器,報(bào)警提示
var oDiv=document .getElementById(‘div1’)
oDiv.className = 'box1'
js中括號操作屬性
window.onlond=function() 瀏覽器對象。bom對象。定時(shí)器,報(bào)警提示
var oDiv=document .getElementById(‘div1’)
var oDiv2=document .getElementById(‘div2’)
oDiv2。innerHTML div里面寫內(nèi)容
oDiv2。innerHTML <a>www.d.fd</a>套標(biāo)簽
doucment.write 重繪整個(gè)頁面。innerHTML 修改某個(gè)部分 面試題。
var attr = 'color'
oDiv.['style'] [attr]= red
變量【】表示;
’’代表值;
js函數(shù)
function aa()
{
alert('sad')
}
aa();
body
<input type='button' value='xxx' onclick='aa'>
變量和函數(shù)預(yù)解析
alert(a)
var a =123
undefind 變量解析只是聲明提前,賦值沒提前。
alert(c) 報(bào)錯(cuò)
函數(shù)可以再調(diào)用后寫函數(shù)主程序,整個(gè)預(yù)解析,提前。
匿名函數(shù)
window.onlond=function() { 瀏覽器對象。bom對象。定時(shí)器,報(bào)警提示
var oDiv=document .getElementById(‘div1’)
oDiv。onclick=myaleart 加括號賦值直接調(diào)了。
function myaleart(){
alert(''121w2)
}
```
匿名函數(shù)
oDiv。onclick=function(){
alert('111')
}
}
函數(shù)傳參
window.onlond=function() { 瀏覽器對象。bom對象。定時(shí)器,報(bào)警提示
var oDiv=document .getElementById(‘div1’)
function changestyle(style,value){
oDiv。style【style】=value style是因?yàn)閭鞯?,但是style里面沒這個(gè),所以用【】
}
changestyle('background,','red')
}
window.onlond=function() { 瀏覽器對象。bom對象。定時(shí)器,報(bào)警提示
var oDiv=document .getElementById(‘div1’)
changestyle('background,','red')
function changestyle(style,value){
oDiv。style【style】=value style是因?yàn)閭鞯模莝tyle里面沒這個(gè),所以用【】
}
}