????????????????????????????????????????????????????????js中括號操作屬性
<script type="text/javascript">
window.onload = function(){
var oDiv = document.getElementById('div1');
//oDiv.style.color = 'red';//red必須加引號,否則會認(rèn)為它是一個變量,引起來會認(rèn)為它是一個值芒篷,賦值給=號左邊
var attr = 'color';
// oDiv.style[attr] = 'red';
/* 通過[]操作屬性可以寫變量 */
oDiv['style'][attr] = 'red';
/* 通過innerHTML可以讀寫元素包括的內(nèi)容 */
alert(oDiv.innerHTML);//讀取標(biāo)簽里面包裹的元素遵岩,即“這是一個div元素”
var oDiv2 = document.getElementById('div2');
// oDiv2.innerHTML = '這是第二個div元素';//向div標(biāo)簽中插入內(nèi)容
oDiv2.innerHTML = "<a ;//向div標(biāo)簽中插入超鏈接標(biāo)簽
..................................................................................................................................................
document.write和innerHTML的區(qū)別
document.write只能重繪整個頁面
innerHTML可以重繪頁面的一部分
}
</script>
..........................................................................................................................................................
document.write和innerHTML的區(qū)別
document.write只能重繪整個頁面
innerHTML可以重繪頁面的一部分
..........................................................................................................................................................
? ??????????????????????????????????????????????js函數(shù)
<script type="text/javascript">
function aa(){
alert('hello!');
}
//直接調(diào)用
aa();
</script>
..........................................................................................................................................................
<body>
<input type="button" name="" value="彈框" onclick="aa()" />
</body>
..........................................................................................................................................................
? ??????????????????????????????????????????????????????js換膚
<script type="text/javascript">
window.onload = function(){
/* 提取行間事件 */
var oBtn01 = document.getElementById('btn01');
var oBtn02 = document.getElementById('btn02');
oBtn01.onclick = skin01;//這里不能寫skin01()届吁,這樣寫就馬上執(zhí)行了
oBtn02.onclick = skin02;
}
function skin01(){
var oLink = document.getElementById('link1');
oLink.href = "css/1.css";
}
function skin02(){
var oLink = document.getElementById('link1');
oLink.href = "css/2.css";
}
</script>
..........................................................................................................................................................
<body>
<!--
行間調(diào)用函數(shù)
<input type="button" name="" value="皮膚01" onclick="skin01()" />
<input type="button" name="" value="皮膚02" onclick="skin02()" /> -->
<input type="button" name="" value="皮膚01" id="btn01" />
<input type="button" name="" value="皮膚02" id="btn02" />
<div class="box01"></div>
<div class="box02"></div>
</body>