Javascript学习笔录7(学会用Object对象、属性、方法-1)

25 篇文章 0 订阅
23 篇文章 0 订阅

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>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值