zoukankan      html  css  js  c++  java
  • 动态设置Input框的默认值

    $("#projectcode").setDefauleValue();

    //设置合同编号的默认值
    $.fn.setDefauleValue = function() {
    var defauleValue = $(this).val();
    function p(s) {
    return s < 10 ? '0' + s : s;
    }
    var myDate = new Date();
    //获取当前年
    var year=myDate.getFullYear().toString().substr(-2,2);
    alert(year);
    //获取当前月
    var month=myDate.getMonth()+1;
    //获取当前日
    var date=myDate.getDate();
    var h=myDate.getHours(); //获取当前小时数(0-23)
    var m=myDate.getMinutes(); //获取当前分钟数(0-59)
    var s=myDate.getSeconds();
    var now=year+p(month)+p(date)+p(h)+p(m)+p(s);
    function randomNum(n){
    var t='';
    for(var i=0;i<n;i++){
    t+=Math.floor(Math.random()*10);
    }
    return t;
    }
    var randomCode = now+randomNum(4);
    defauleValue = randomCode;
    $(this).val(defauleValue).css("color","#999");

    return this.each(function() {
    $(this).focus(function() {
    if ($(this).val() == defauleValue) {
    $(this).val("").css("color","#000");//输入值的颜色
    }
    }).blur(function() {
    if ($(this).val() == "") {
    $(this).val(defauleValue).css("color","#999");//默认值的颜色
    }
    });
    });
    }

  • 相关阅读:
    网站图片轮播效果
    图片处理类
    字符串处理帮助类
    css3高级选择器
    JQuery选择器大全
    ASCII码表
    jQuery选择器大全
    OpenFileDialog无法弹出的解决方法
    socket学习目录
    ps-抠图
  • 原文地址:https://www.cnblogs.com/yuner-angel/p/8072690.html
Copyright © 2011-2022 走看看