2015年9月3日 星期四

深入淺出Ajax -- Ajax應用程式設計[2]


  • 當瀏覽器載入xhtml檔時,<script>標籤會請他載入js檔,在js當中,function外的程式碼會立刻被執行,而function會被瀏覽器的js直譯器建立,但不會被執行。
  • window.load不在function中,所以會馬上被執行,其所指定的function則會在xhtml參照的所有檔案被載入後(在User能使用網站前),接著執行。
  • 把會重複使用到的程式碼放在一個公用程式碼檔案中(util.js),並且把它放在應用程式特定的程式碼之前(先include的感覺)。
  • 大部分的"非Microsoft瀏覽器"可以支援XMLHttpRequest,所以要為IE做特別的request方式。
使用JavaScript改變CSS:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*CSS*/
// set shape
#test {width: 100px; height: 100px;}

// id = "test"; class = "demo1"
#test.demo1 {background-color: red}

// id = "test"; class = "demo2"
#test.demo2 {background-color: blue}

/*JavaScript*/
function changeCSS() {
 document.getElementById("test").className = "demo1";
}

沒有留言:

張貼留言