【问题标题】:to place current date as placeholder initially in the input field datepicker bootstrap最初将当前日期作为占位符放置在输入字段 datepicker 引导程序中
【发布时间】:2015-01-07 09:26:58
【问题描述】:

我希望在日期选择器中将所有字段设置为当前日期,开始日期为当前日期前两年,结束日期为今天日期。但是输入字段中的占位符不是当前日期

$(document).ready(function() {
		/*var $datepicker = $( "#datepicker" );
        $datepicker.datepicker();
        $datepicker.datepicker('setDate', new Date());*/
		
		$('input#datepicker').click(function() {
		  // document.getElementById('datePicker').valueAsDate = new Date();
		
            //alert($(this).attr('id'));
			   alert("you can only post interviews not more older than the last two years!!!");
           });
		
		
		// adding todays date as the value to the datepickers.
		
        var d = new Date();
        var curr_day = d.getDate();
        var curr_month = d.getMonth() + 1; //Months are zero based
        var curr_year = d.getFullYear();
        var eutoday = curr_day + "-" + curr_month + "-" + curr_year;
        var ustoday = curr_month + "-" + curr_day + "-" + curr_year;
        $("div.datepicker input").attr('value', eutoday);
        $("div.usdatepicker input").attr('value', ustoday);
            //document.getElementById('datePicker').value = new Date().toDateInputValue();
        //calling the datepicker for bootstrap plugin
        // https://github.com/eternicode/bootstrap-datepicker
        // http://eternicode.github.io/bootstrap-datepicker/
        $('#datepicker').datepicker({
		   // setDate: new Date(),
		//   datepicker('setDate', new Date())
			//document.getElementById('datePicker').valueAsDate = new Date();
			//document.getElementById('datePicker').value = new Date().toDateInputValue();
            autoclose: true,
			
          //  startDate: new Date()
			
    startDate: '-24m',
    // endDate: '+2d'
	endDate: new Date()

        });
    });

【问题讨论】:

    标签: javascript jquery html twitter-bootstrap


    【解决方案1】:
    $( document ).ready(function() {
        var date = Date();
       $("#yourdateinput").attr("placeholder",date);
    });
    

    【讨论】:

      【解决方案2】:

      你可以试试这个:-

      $( document ).ready(function() {
          var date = Date();
          document.getElementById("yourInputID").value = date;
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-17
        • 1970-01-01
        • 2012-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多