zoukankan      html  css  js  c++  java
  • 开发中 常用 js 记录(一)

    (1)获得URL参数

    function GetQueryString("url参数名") {
         var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
         var r = window.location.search.substr(1).match(reg);
         if (r != null) return (r[2]);
         return null;
    }

    (2)获得url 中文参数转码

         decodeURI(GetQueryString("url参数名"))


    (3)滑动到底部产生事件

    $(window).scroll(function() {
         if ($(window).scrollTop() + $(window).height() == $(document).height()) {


         }
    });

    (4)价格保留两位小数

         (价格).toFixed(2)


    (5)延迟执行事件

    window.setTimeout(function () {
         window.location.href = 'www.cnblogs.com/huangenai/';
    }, 2500);


    (6)点击事件

    $(document).on('touchstart click', ".profile_li",function(e) {


    e.preventDefault();

       });

    (7)ajax请求数据

    $('#btnOK').click(function () {
    $.ajax({
         type: "POST",
         url: '/Home/index',
         data: { }, //参数
         datatype: "html",
         success: function (data) {

         },
         error: function () {
     
         }
        });
    });

    (8)获得验证码倒计时效果

    <input id="btn"  value="获取验证码"/>

    var wait = 60;
    document.getElementById("btn").disabled = false;
    function time(o) {
         if (wait == 0) {
         o.removeAttribute("disabled");
         o.value = "获取验证码";
         wait = 60;
         } else {
         o.setAttribute("disabled", true);
         o.value = "重新发送(" + wait + ")";
         wait--;
         setTimeout(function() {
         time(o);
         },
         1000);
         }
    }

  • 相关阅读:
    Java集合一
    集合类视图
    NIO
    IO补充
    线程图
    线程池
    Callable
    element-ui upload组件上传图片时限制图片宽高
    vue-router 使用a链接跳转至二级子页面偶尔会出现地址栏看不见路由和参数的情况
    vue中引入jquery报错问题
  • 原文地址:https://www.cnblogs.com/huangenai/p/5372359.html
Copyright © 2011-2022 走看看