zoukankan      html  css  js  c++  java
  • Javascript常用

    <script type="text/javascript"></script>
    页面加载后调用
         1.window.onload=function(){}          图片完全加载之后提示
         2.$(function(){});
         3.$(document).ready(function(){});
        

    浏览器窗口的内部高度
         var w=window.innerWidth
         || document.documentElement.clientWidth
         || document.body.clientWidth;
    浏览器窗口的内部宽度
         var h=window.innerHeight
         || document.documentElement.clientHeight
         || document.body.clientHeight;

        window.open() - 打开新窗口
        window.close() - 关闭当前窗口
        window.moveTo() - 移动当前窗口
        window.resizeTo() - 调整当前窗口的尺寸
    页面加载后触发
         window.onload=function (){
         }
         http://www.w3school.com.cn/jsref/dom_obj_window.asp
    刷新页面
         location.replace(location.href);
    回退到上一页
         history.go(-1);
        
        
    js获取控件
         document.getElementById("zx");
         document.getElementsByName("hh")[0];
    js获取html
         document.getElementById("zx").innerHTML;
         document.getElementById("zx").innerHTML="<b>我们约会吧~</b>";
    jq获取对象
         $("#XXX") '获得 id=XXX 的元素对象(id可以是标签的id或CSS样式id) 常用
         $(".abc") ' 获得样式class的名字是.abc的元素对象 常用
         $("div") ' 标签选择器 选择所有的div元素 常用
         $("input[name='username']") 获得input标签中name='userName'的元素对象 常用
         http://www.jb51.net/article/45854.htm
    //隐藏控件
         $('#BgDiv').hide(); 
    //显示控件
         $("#contorlModel").show();
    //给控件增加css属性
         $(“#div01”).css({position: "absolute"});
         $(“#div01”).css("top",temp);
    //attr()函数用于设置或返回当前jQuery对象所匹配的元素节点的属性值。
         $("#resourceExist").attr("value");
         $("img").attr("width","180");
    //移除控件的属性
         $(id).removeAttr("onmouseover");
    //将一个对象追加到另外一个对象内部
         $(textId).append(html);
    //显示对话框
         $("#browserType").dialog({         
                   modal:true,
                   closed:false,
                   closable:false,
                   title:"警告信息",
                   400,
                   height:150,
                   buttons:[{
                        text:"返回",
                        handler:function(){
                             history.back();
                        }
                   }]
              });
    //获取对象的所有方法和属性    
    function displayProp(obj){   
        var names="";      
        for(var name in obj){      
           names+=name+": "+obj[name]+", "; 
        } 
        alert(names); 
    }
    //获取path
    function getRootPath(){ 
        // http://localhost:8088/test/test.jsp 
        var curPath=window.document.location.href;
        // test/test.jsp 
        var pathName=window.document.location.pathname;
        var pos=curPath.indexOf(pathName);
        // http://localhost:8088 
        var localhostPaht=curPath.substring(0,pos); 
        ///test 
        var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1); 
        return(localhostPaht); 

    //1.判断浏览器类型:
    var browser={
             versions:function(){
             var u = window.navigator.userAgent;
             return {
                 trident: u.indexOf('Trident') > -1, //IE内核
                 presto: u.indexOf('Presto') > -1, //opera内核
                 webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                 mobile: !!u.match(/AppleWebKit.*Mobile/) || !!u.match(/Windows Phone/) || !!u.match(/Android/) || !!u.match(/MQQBrowser/), //是否为移动终端
                 ios: !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
                 iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者安卓QQ浏览器
                 iPad: u.indexOf('iPad') > -1, //是否为iPad
                 webApp: u.indexOf('Safari') == -1 ,//是否为web应用程序,没有头部与底部
                 weixin: u.indexOf('MicroMessenger') == -1 //是否为微信浏览器
             };
             }()
    };
    //如果是android和平板
    var browserType=browser.versions.mobile ||browser.versions.android

    //2.获取当前时间并返回String字符串
    function getNowDateOfString(){
         var dateString="";
         var date=new Date();
         dateString=date.getFullYear()+"-"+((date.getMonth()+1)<10?"0":"")+(date.getMonth()+1)+"-"+(date.getDate()<10?"0":"")
         +date.getDate()+" "+(date.getHours()<10?"0":"")+date.getHours()+":"+(date.getMinutes()<10?"0":"")+date.getMinutes()+":"
         +(date.getSeconds()<10?"0":"")+date.getSeconds();
         return dateString;
    }
    //定时器
    var intervalID =  setInterval(function(){
      if(checkLoaded(spokencore)){ 
                //初始化flash中初始参数问题
              spokencore.initRecordArray(pageIndex);
              spokencore.setModelIndex(0);
              init();
          clearInterval(intervalID); 
          intervalID = null; 
      } 
    },60);

    //检查SWF是否加载完成
    function checkLoaded(flash){
         try{ 
          return Math.floor(flash.PercentLoaded()) == 100 
      }catch(e){ 
          return false; 
      } 
    }

    function GetRequest() {
              var url = location.search; //获取url中"?"符后的字串    
              var theRequest = new Object();
              if (url.indexOf("?") != -1) {
                   var str = url.substr(1);
                   strs = str.split("&");
                   for ( var i = 0; i < strs.length; i++) {
                        theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                   }
              }
              return theRequest;

    }
    $.ajax({
        url:"test.json",
        type: "GET",
        data: {username:$("#username").val()},
        dataType: "json",
        beforSend:function(){
             // 禁用按钮防止重复提交
            $("#submit").attr({ disabled: "disabled" });
        },
        complete:function(msg){
            //请求完成后调用的回调函数(请求成功或失败时均调用)
        } ,
        error:function(msg){
            //请求失败时被调用的函数
        } ,
        Sucess:function(msg){
            //请求成功后调用的回调函数
        }
    });
  • 相关阅读:
    Ext.form.RadioGroup
    Ext:ComboBox实战
    Ext.Ajax.request
    下拉菜单
    为Ext添加下拉框和日期组件
    点击grid单元格弹出新窗口
    好用的sql
    数据库连接池总是断开
    POI 自用API
    String 操作
  • 原文地址:https://www.cnblogs.com/xiaoyu123/p/5386484.html
Copyright © 2011-2022 走看看