2018-06-25 js表单事件、三个高度和Ajax异步通讯技术

表单事件:

  onfocus -> 表单控件得到焦点时触发;

    obj_ipt.onfocus=function(){}; 

  onblur -> 表单控件失去焦点时;

  onchange -> 表单控件内容被改变时;

  onselect -> 控件被选择时;

  onsubmit -> 当表单提交时;

  onreset -> 当表单重置时;

 表单对象方法:

  select() -> 对象被选中;

    ipt_obj.select();

  blur() -> 失去焦点

  focus() -> 得到焦点

  click() -> 被点击

  submit() -> 表单被提交

  Reset() -> 表单被重置

三个高度:

  h1=document.documentElement.clientHeight ->浏览器的(有效)可视高度

  h2=document.documentElement.scrollHeight ->浏览器的总高度;

  h3=document.documentElement.scrollTop -> 已滚动的高度

  h3 + h1 = h2

Ajax无刷新技术

  xhr = new XMLHttpRequest();-> 生成ajax对象

  xhr.open('post','index.php?name='+name,true) ->js post请求index.php文件,并将name传给后台,ture为异步通讯,false则为同步

  xhr.send -> 发出异步通讯请求

  //监听整个通讯过程

  xhr.onreadystatechange=function(){

  //xhr.readyState的值为4 则请求结束,可以获取返回值判断后台执行的成功与否

    if(xhr.readyState == 4){

      if(r=='1'){

        //成功

      }else{

        //失败

      }

    }

  }

猜你喜欢

转载自www.cnblogs.com/miaoxingren/p/9226194.html