zoukankan      html  css  js  c++  java
  • 《Head First JavaScript》 学习笔记


      <scipt type="text/javascript" src"cookie.js"> </script>  //脚本署名方法

      <body onload ="resizeRock(); greetUser();" onresize = "resizeRock();">  //重调浏览器触犯的事件

        document.getElementById("rockImg").style.height = "100px";

     

        var showTime = {"12:30", "2:45", "5:00", "7:15", "9:30"}; //数组创建

     

      var seats = new Array(new Array(9),new Array(9), new Array(9), new Array(9));

        var seats = [ [ , , ,], [ , , ,], [ , , ,], [ , , ,]];

     

      var myShowStatus = showSeatStatus;

        回调函数 脚本外部调用 onload ; 浏览器会调用它们

        联结事件:联结回调函数与事件,引用函数;

        函数名称后面没有括号,因为此时并非意图运行函数,只是想引用函数;

        函数字面量 documen.getElementById("seat26").onclick = function(evt){
                                shouSeatStatus(26);
                                };


                回调函数必须联结到onload事件处理器中;

     

      name 可独一无二地识别表单中的域;

    <input id="zipcode" name="zipcode" type="text" size = "5" />
    onfocus onblur //onchange;
    <input id="phone" name="phone" type="text" size="12" onblur = "validateNonEmpty(this,document.getElementById('phone_help'));"/>

      <span id="phone_help" class="help"></span>

        inputField.value.length

     

    正则表达式 regular expression

      / . d w s ^ $/
    .任何字符 d数字 w字母或数字 s空格 ^起始模式 $结束模式
            regular expression / +expression +/


    限定符:
      * 0次以上 + 1次以上 ?0或1 {n} n次 {min,max} ()集合字母 (this|that)
      集合中 [ ] 匹配可选符

     

     

    document.getElementsByTagName("img")[3]

    innerHTML

    document.getElementById("story").innerHTML =
    "you are <strong> not</strong> alone";

    nodeValue nodeType childNodes firstChild lastChild

    DOM改变节点文本三步骤
      var node = document.getElementBtId("stroy");
      while(node.firstChild)
      node.removeChild(node.firstChild);//移除所有节点
      node.appendChild(document.createTextNode("Ok, maybe you are alone."));//后续接上

    鼠标的触发的两种事件  onmouseover / onmouseout

     

     

    创建HTML元素
      var decisionElem = document.creatElement("p");
      deicisionElem.appendChild(document.createTextNode(" ");

    date对象   setMonth(); getDate(); setYear(); getDay();
    var date = new date();
    var blogDate = new Date("04/17/2018")

     

    排序方法  sort() 默认升序排列

    比较函数 camparison function:
    function capare(x,y){
    return x-y;
    } //<0 x排y前面 >0 y前

    blog.sort{(function(blog1,blog2){return blog2.date - blog1.date;}} //比较函数提供只提供给sort()使用,不会出现在别的地方,所以可以省略函数名称

     

    以string为对象

      属性 length  方法indexOf(); //检索不到时 return -1;

            charAt(); //检索单一字符  toLowerCase();toUpperCase();

     

    MATH

      PI =3.14  常量    round()四舍五入取整  ceil()向上取整   floor()上下取整   random()随机

     

    方法存储在类里

     

     类层用 prototype

      blog.prototype.toHTML = function() {

        }

     

    类特性 blog.prototype.signature = " ...";  使用时调用类特性 既实例特性吧  blog.signature 或者 this.signature; 

     

          AJAX: 可以用于请求任何数据,动态

    XML :类似于HTML 可以用自己定义的标签标示数据 例如  <books>   只是一种文本格式   

     

    XMLHttpRequest : 内置于JavaScript的函数 用于发起请求和处理请求 ,复杂;

        属性:readyState ;请求的状态代码  status;HTTP的请求状态代码  onreadystatechange;  responseText;  responseXML;

        方法: abory();  open();  send();

     

     

    Get 与 Post 

        get请求是从服务器上获取数据;

            request.open("GET", "bolg.xml",  true); // always asynchronous (true);

            request.send( null); // get无数据可以发送 所以是null;

     

        post请求是把数据发送给服务器;

            request.open("POST", "addblogentry.php", true );

            request.setRequestHeader("Content-Type", "application/x-www-form-ulencoded; charset = UTF - 8");

            requese.send ("flkasdjflhffnaksljnfkdlsjnf.png");

     

    AjaxRequest: 

      底层的XMLRequest对象储存在 request特性里面:

      方法:getReadyStatus();  getStatus();  getResponseText();  getResponseXML();  send();

          发起Ajax请求 :   

                var ajaxReq = new AjaxRequest();

     

    AjaxReques.prototype.send = function(type, url, handeler, postDataType, postData) {

      if(this.request != null){

        //Kill the previous request 

        this.request.abor();

     

        //Tack on a dummy parameter to override brower caching

        url  += "?dummy" + new Date().getTime();

     

        try{

          this.request.onreadystatechange = handler;

          this.request.open(type, url, true);

          if(tyoe.toLowerCase() == "get"){

            //Send a GET request; no data invoived 

            this.request.send (null);

          }else{

            //Send a POST request; the last argument is data 

            this.request.setRequestHeader("Content - Type", postDataType);

            this.request.send(postData);

          }

        }catch(e){

        alert("Ajax error conmunicating with the seerver. " + "Details :" +e );

        }

      }

    }

     

    所以  

    var ajaxReq = new ajaxRequest();

    ajaxReq.send (type, url, handler, postDataType, postData);

      type:get 或者 post

      url: 服务器的URL

      handler: 处理响应的回调函数

      postDataType: 被传送的数据类型 只用于post  :charset = UTF-8 ;

     

    function getText(element)

     

    分开创建JS 文件

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    算法题之丢手绢问题
    Java接口成员变量和方法默认修饰符
    清空select下拉框的方法
    Java基础数据类型的默认值
    JVM内存区域划分
    Java中匿名内部类
    Java值传递
    部署web Service到tomcat
    Tomcat环境下配置数据源
    遇到和需要解决的问题
  • 原文地址:https://www.cnblogs.com/ILoveMyJob/p/8868340.html
Copyright © 2011-2022 走看看