zoukankan      html  css  js  c++  java
  • js

    1.arguments:不定参  

    function sum()
    {

    arguments.lenght :根据所传参数的不同,数量改变

    }

    sum(1,2,4)
    2.定义匿名函数 :(function sum(){

    })

    好处:在执行完后就会销毁

    3.currentStyle.getComputedStyle 获取样式表里面的属性:currentStyle:不兼容Ie ,getComputedStyle :不兼容火狐

    function getStyle(obj, attr) 

    if(obj.currentStyle) 

    return obj.currentStyle[attr]; 

    else 

    return getComputedStyle(obj,false)[attr]; 

    4.push:末尾添加,pop:尾部删除,shift:头部删除,unshift:头部添加

    5.在js 里面

    var s='23';  s[0]=chatAt(0)=2;  chatAt:兼容性好 

    6.ajax 异步和同步

      $("#insuranceWarrantyRecordExpressInfo_SendProvinceName").val("@insuranceWarrantyRecordExpressInfo.SendProvinceName").change();

    在同时给一个控件赋值和执行ajax 请求,在异步情况下可能会先完成ajax ,此时将会出现问题,获取不到控件的值

    同步:js本身是一个阻塞的语言,需要逐行读取代码,如果某一个程序出错,即不再执行后面所有代码;

    异步:不管程序相应结果都会执行所有代码;

     7.js 图片压缩

    $(document).ready(function () {
    function fileChange(e) {
    var f = e.files[0];
    var _size = f.size;
    //console.log(f);
    var FR = new FileReader();
    FR.readAsDataURL(f);
    FR.onload = function (f) {
    compressImg(this.result, 1200,1200, function (data) {
    //$("#newImg").attr("src",data);//保存图片压缩后的64位编码
    $('#aaa').attr('src', data);
    });
    };
    }
    document.getElementById("image").addEventListener("change", function () {
    fileChange(this);
    }, false);
    function compressImg(imgData, maxHeight,maxWidth, onCompress) {
    if (!imgData) { return false };
    onCompress = onCompress || function () { };
    maxHeight = maxHeight || 100; //默认最大高度1000px
    var canvas = document.createElement('canvas');
    var img = new Image();
    img.src = imgData;

    img.onload = function () {
    var sW = img.width, sH = img.height;
    debugger
    if (img.height > maxHeight || img.width > maxWidth) //将**改成c#中的或者操作符号
    {
    if ((img.width * maxHeight) > (img.height * maxWidth)) {
    sW = maxWidth;
    sH = (maxWidth * img.height) / img.width;
    }
    else {
    sH = maxHeight;
    sW = (img.width * maxHeight) / img.height;
    }
    }

    var ctx = canvas.getContext("2d");
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    canvas.width = sW;
    canvas.height = sH;
    ctx.drawImage(img, 0, 0, sW, sH);
    onCompress(canvas.toDataURL("image/jpeg",70)); //压缩质量
    //console.log(canvas.toDataURL("image/jpeg"));
    //$('#IMAGE_URL').val(canvas.toDataURL("image/jpeg",70)) //压缩质量
    };
    }
    });

    8. 地图导航

    $(function () {
    let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
    let htmlHeight = document.documentElement.clientHeight || document.body.clientHeight;
    //alert(htmlWidth)
    let htmlDom = document.getElementsByTagName('html')[0];
    htmlDom.style.fontSize = htmlWidth / 10 + 'px';

    //设置腾讯地图区域初始高度
    $(".mainContainer").css("height", htmlHeight + "px");
    })

    9.地图定位

    <input type="text" id="address" placeholder="地址" style=" 300px; height: 30px; margin: 20px 0 0 0;" />

    $(document).ready(function () {

    $('#search_address').click(function () {
    var address = $.trim($('#address').val());
    if (address != undefined && address != '') {
    var url = 'http://api.map.baidu.com/geocoder/v2/?ak=eIxDStjzbtH0WtU50gqdXYCz&output=json&address=' + encodeURIComponent(address);
    //根据地点名称获取经纬度信息
    $.ajax({
    type: "POST",
    url: url,
    dataType: "JSONP",
    success: function (data) {
    if (parseInt(data.status) == 0) {
    $("#lng").html("经度:" + data.result.location.lng);
    $("#lat").html("纬度:" + data.result.location.lat);
    }
    }
    });
    }
    });
    });

  • 相关阅读:
    LeetCode 32. 最长有效括号(Longest Valid Parentheses)
    LeetCode 141. 环形链表(Linked List Cycle)
    LeetCode 160. 相交链表(Intersection of Two Linked Lists)
    LeetCode 112. 路径总和(Path Sum)
    LeetCode 124. 二叉树中的最大路径和(Binary Tree Maximum Path Sum)
    LightGBM新特性总结
    sql service 事务与锁
    C#泛型实例详解
    C# 中的委托和事件(详解)
    C# DateTime日期格式化
  • 原文地址:https://www.cnblogs.com/lp73/p/7400654.html
Copyright © 2011-2022 走看看