Javascript學習筆錄7(學會用Object對象、屬性、方法-1)

1 獲得頁面的背景顏色

bgColor

2 選擇文本,使用DOM對象

document.form1.ta1.select() 這樣層次分明的抓到元素內容——DOM

3 <script></script>可以出現在html的任何位置

4 substr的用法,截取字符串

5 創建對象  New,獲得當前時間

6 有些門戶網站註冊,填好的text,如果鼠標再次選中,則整個字符串全部選中——this.select()

7 查看對象屬性

具體代碼:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Js5.aspx.cs" Inherits="Javascript_Js5" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Javascript學習筆錄7</title>
</head>
<body bgcolor="white" ><%--style="background-color:Silver"   CSS樣式優先級比bgcolor高--%>
    <form id="form1" runat="server">
    <div>
        <script>//<%--script腳本可以加到網頁的任何地方--%>
            document.write("頁面背景色:"+document.body.bgColor); //document.bgColor 也是可以的
        </script>
        <br />
        <textarea name="ta1" >pdfpdapafdfeoewreupwuroptjnxmmkfwqwe]1\2i3irejdfwefojwe390754y</textarea>
        <input type="button" value="選擇文本" οnclick="document.form1.ta1.select()" />
        <input type="button" value="顯示文本" οnclick="document.write(document.form1.ta1.value)" />
        <%--document.form1.ta1.value不是字符串,而是變量所以不用單引號--%>
        <br />
        <input type="radio" name="radio1"/>男
        <input type="radio" name="radio2" />女
        <input type="text" name="txtHello" value="Hello" />
        <script>
            document.form1.txtHello.value="sjdfswierh";
            document.form1.radio1.checked=true;
        </script>
        <br />
       <script>
         var str1="123456789";
         document.write(str1+"</br>");
         var str2=str1.substr(5);//6789,從字符串0計數,第五個開始截取
         document.write(str2+"</br>")
         document.write("輸出結果:"+Math.PI*Math.pow(5.0,2));//Javascript區分大小寫
       </script>
       <br />
       <script>
       today=new Date();
       document.write("今天是"+(today.getMonth()+1)+"月"+today.getDate()+"日"+"</br>");//.getMonth()方法比實際月份少1,需要加1
       document.write("現在是:"+today.toLocaleString()+"</br>");
       </script>
       <input type="text" name="txt4" value="adfewf" οnclick="this.select()" />
       </br>
       <script>
       for(properties in window)
       {
        document.write("window."+properties+"="+window[properties]+"</br>");
       }
       </script>
    </div>
    </form>
</body>
</html>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章