• JavaScript基础-3


          在javascript中有一个非常重要的对象就是DOM对象,DOM对象起到了对页面中的对象进行操作,我们许多效果与功能都要通过DOM实现。

        有以下常用的基本对象:

        数字对象:Number

        字符串对象:String

        数组对象:Array

        数学对象:Math

        日期对象:Date

        全局对象:Global

    • Number对象的demo:
       1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
       2: <html>
       3:     <head>
       4:         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
       5:         <title>Untitled Document</title>
       6:         <script type="text/javascript">
       7:             alert("Number的最大数是:"+Number.MAX_VALUE);
       8:             alert("Number的最小数是:"+Number.MIN_VALUE);
       9:         
      10:         </script>
      11:     </head>
      12:     <body>
      13:     </body>
      14: </html>
    • String对象的demo:
       1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
       2: <html>
       3:     <head>
       4:         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
       5:         <title>Untitled Document</title>
       6:         <script type="text/javascript">
       7:             function TestString(){
       8:                 alert("我们开始试验String对象");
       9:                 
      10:                 var txtStringValue = document.getElementById("txtStringDemo").value;
      11:                 alert("TextBox中的值是" + txtStringValue);
      12:                 
      13:                 alert("TextBox中的第一字符的值是" + txtStringValue.charAt(0));
      14:                 for(i=0;i<txtStringValue.length;i++)
      15:                 {
      16:                     alert("第"+i+"字符的值是"+txtStringValue.charAt(i));
      17:                 }
      18:                 alert("将TextBox中第一字符转化为ASCII码" + txtStringValue.charCodeAt("0"));                
      19:                 
      20:                 
      21:                 
      22:             }
      23:         </script>
      24:     </head>
      25:     <body>
      26:         <form id="StringFormDemo">
      27:             <input type="text" id="txtStringDemo" value="">
      28:             <input type="button" id="btnSubmint" value="试验字符串对象" onclick="TestString()">
      29:         </form>
      30:     </body>
      31: </html>
       1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
       2: <html>
       3:     <head>
       4:         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
       5:         <title>Untitled Document</title>
       6:         <script type="text/javascript">
       7:             function TestString(){
       8:             
       9:                 var txtStringValue = document.getElementById("txtStringDemo").value;
      10:                 
      11:                 alert("txtStringDemo中的值是" + txtStringValue);
      12:                 
      13:                 var filenameExt = txtStringValue.substring(txtStringValue.lastIndexOf(".") + 1);
      14:                 
      15:                 alert("FileName extense:" + filenameExt);
      16:                 //比较之前先转化成为小写的字母
      17:                 if (filenameExt.toLowerCase() != "jpg") {
      18:                     alert("对不起只支持jpg上传");
      19:                 }
      20:                 else {
      21:                     alert("上传成功!");
      22:                 }
      23:                 
      24:                 
      25:             }
      26:             
      27:             function ChangeName(){
      28:                 var txtStringValue = document.getElementById("txtStringDemo").value;
      29:                 
      30:                 var filename = txtStringValue.substring(txtStringValue.lastIndexOf("\\") + 1);
      31:                 var txtFile=document.getElementById("txtFileName");
      32:                 txtFile.value=filename;
      33:             }
      34:         </script>
      35:     </head>
      36:     <body>
      37:         <form id="StringFormDemo">
      38:             <input type="file" id="txtStringDemo" value="" onchange="ChangeName()">
      39:             <input type="text" id="txtFileName">
      40:             <input type="button" id="btnSubmint" value="试验字符串对象" onclick="TestString()">
      41:         </form>
      42:     </body>
      43: </html>

     

  • 相关阅读:
    python常用函数 A
    从__name__=='__main__'说到__builtin__
    python常用魔法函数
    MySQL内核:InnoDB存储引擎 卷1
    “胡”说IC——菜鸟工程师完美进阶
    恶意代码分析实战
    转折点:移动互联网时代的商业法则
    大型网站系统与Java中间件实践
    《Node.js实战(双色)》作者之一——吴中骅访谈录
    网站运维技术与实践
  • 原文地址:https://www.cnblogs.com/chu888chu888/p/1336200.html
Copyright © 2020-2023  润新知