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>