JavaScript基礎知識(四)
31 設置日期輸出格式
1: <script language=」JavaScript」>
2: var thisDate = new Date();
3: var thisTimeString = thisDate.getHours() + 「:」 + thisDate.getMinutes();
4: var thisDateString = thisDate.getFullYear() + 「/」 + thisDate.getMonth() + 「/」 + thisDate.getDate();
5: document.write(thisTimeString + 「 on 「 + thisDateString);
6: </script>
32 讀取URL參數
1: <script language=」JavaScript」>
2: var urlParts = document.URL.split(「?」);
3: var parameterParts = urlParts[1].split(「&」);
4: for (i = 0; i < parameterParts.length; i++) {
5: var pairParts = parameterParts.split(「=」);
6: var pairName = pairParts[0];
7: var pairValue = pairParts[1];
8: document.write(pairName + 「 :「 +pairValue );
9: }
10: </script>
你還覺得HTML是無狀態的麼?
33 打開一個新的document對象
1: <script language=」JavaScript」>
2: function newDocument() {
3: document.open();
4: document.write(「<p>This is a New Document.</p>」);
5: document.close();
6: }
7: </script>
34 頁面跳轉
1: <script language=」JavaScript」>
2: window.location = 「
[url]http://www.liu21st.com/[/url]
」; 3: </script> 35 添加網頁加載進度窗口 1: <html> 2: <head> 3: <script language='javaScript'> 4: var placeHolder = window.open('holder.html','placeholder','width=200,height=200'); 5: </script> 6: <title>The Main Page</title> 7: </head> 8: <body> 9: <p>This is the main page</p> 10: </body> 11: </html> JavaScript就這麼回事3:圖像 36 讀取圖像屬性 1: <img src="/」p_w_picpath1.jpg"」 name=」myImage」> 2: <a href=」# 」 onClick=」window.alert(document.myImage.width)」>Width</a> 3: 37 動態加載圖像 1: <script language=」JavaScript」> 2: myImage = new Image; 3: myImage.src = 「Tellers1.jpg」; 4: </script> 38 簡單的圖像替換 1: <script language=」JavaScript」> 2: rollImage = new Image; 3: rollImage.src = 「rollImage1.jpg」; 4: defaultImage = new Image; 5: defaultImage.src = 「p_w_picpath1.jpg」; 6: </script> 7: <a href="/」myUrl"」 onMouseOver=」document.myImage.src = rollImage.src;」 8: onMouseOut=」document.myImage.src = defaultImage.src;」> 9: <img src="/」p_w_picpath1.jpg"」 name=」myImage」 width=100 height=100 border=0> 39 隨機顯示圖像 1: <script language=」JavaScript」> 2: var p_w_picpathList = new Array; 3: p_w_picpathList[0] = 「p_w_picpath1.jpg」; 4: p_w_picpathList[1] = 「p_w_picpath2.jpg」; 5: p_w_picpathList[2] = 「p_w_picpath3.jpg」; 6: p_w_picpathList[3] = 「p_w_picpath4.jpg」; 7: var p_w_picpathChoice = Math.floor(Math.random() * p_w_picpathList.length); 8: document.write(‘<img src=」’ + p_w_picpathList[p_w_picpathChoice] + ‘「>’); 9: </script> 40 函數實現的圖像替換 1: <script language=」JavaScript」> 2: var source = 0; 3: var replacement = 1; 4: function createRollOver(originalImage,replacementImage) { 5: var p_w_picpathArray = new Array; 6: p_w_picpathArray[source] = new Image; 7: p_w_picpathArray[source].src = originalImage; 8: p_w_picpathArray[replacement] = new Image; 9: p_w_picpathArray[replacement].src = replacementImage; 10: return p_w_picpathArray; 11: } 12: var rollImage1 = createRollOver(「p_w_picpath1.jpg」,」rollImage1.jpg」); 13: </script> 14: <a href=」#」 onMouseOver=」document.myImage1.src = rollImage1[replacement].src;」 15: onMouseOut=」document.myImage1.src = rollImage1[source].src;」> 16: <img src="/」p_w_picpath1.jpg"」 width=100 name=」myImage1」 border=0> 17: </a>
歡迎關注本站公眾號,獲取更多信息