drsvw88664 2014-12-22 17:26
浏览 48

在文本框中显示当前星期五的值

i want user open webpage and textbox show value of current friday. i don't know how to use .val here is my code.

$(function() {
$("#dateInput").datepicker({

    //In Datepicker set the Calendar display start with Sunday (by default datepicker starts from Sunday)
    firstDay: 0,

    //Before Populating the Calendar set the Enabled & Disabled Dates using beforeShowDay(Date) function
    beforeShowDay: function (date) {

        //Get today's date
        var sunday = new Date();

        //Set the time of today's date to 00:00:00 
        sunday.setHours(0,0,0,0);

        sunday.setDate(sunday.getDate() - (sunday.getDay() || 0));

        //Set the Date to Sunday
        var saturday = new Date(sunday);
        var thrusday = new Date(sunday);
        var currentday = new Date();

        //0 is sunday 6 is saturday
        var currentdayofweek = currentday.getUTCDay();
        //console.log(currentday, "show currentday");
        //alert('value of currentday=>'+currentday);
        //alert('value of currentday of week=>'+currentdayofweek);
        //location.reload();

        //Now add 6 to Sunday to get the Date of Saturday (End of that Week)
        saturday.setDate(sunday.getDate() + 6);
        //add by kim
        thrusday.setDate(sunday.getDate() + 4);

        //edit by kim
        //return [(date >= thrusday && date <= saturday ), ''];
        // current day of week <5  mean user can select friday only day before friday
        return [(date > thrusday && date < saturday && currentdayofweek < 5), ''];
    }
});
  var temp = $("#dateInput").datepicker("option", "dateFormat", "yy-mm-dd");

  return temp;
});

and here is textbox code.

<input type="text" name="dateInput" id="dateInput"/>
  1. i just want user can select only friday of current week in calendar
  2. and value of friday in current week should show in text box before user select
  • 写回答

2条回答 默认 最新

  • dougang5088 2014-12-22 19:00
    关注

    This will fill the #dateInput input with the date corresponding to the Friday of the current week.

    var date = new Date(),
        day = date.getDay(),
        dif = 5 - day >= 0 ? 5 - day : day - 5;
    date.setTime( date.getTime() + (dif * 24 * 60 * 60 * 1000) );
    $(document).ready(function() {
        $("#dateInput").val( date.getUTCFullYear() + "/" + (date.getMonth()+1) + "/" + date.getUTCDate() );
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <input type="text" name="dateInput" id="dateInput"/>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度