• 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>

     

  • 相关阅读:
    MATLAB画图之多个图以子图的形式合为一个图
    MATLAB画图之图中画局部放大的图中图
    MATLAB画图之自定义图片大小
    "廖雪峰的Git教程"学习笔记
    读书笔记之《程序员必读的职业规划书》
    Python初学者的资源总结
    时间管理去何方
    21天战拖记——Day21:《小强升职记》学习感受(2014-05-24)
    21天战拖记——Day20:整理自己的桌面(2014-05-23)
    21天战拖记——Day19:甘特图的使用(2014-05-22)
  • 原文地址:https://www.cnblogs.com/chu888chu888/p/1336200.html
Copyright © 2020-2023  润新知