javascript - 将当前日期作为占位符最初放置在输入字段 datepicker bootstrap 中

标签 javascript jquery html twitter-bootstrap

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

$(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()

        });
    });

最佳答案

$( document ).ready(function() {
    var date = Date();
   $("#yourdateinput").attr("placeholder",date);
});

关于javascript - 将当前日期作为占位符最初放置在输入字段 datepicker bootstrap 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27816152/

相关文章:

html - HTML "Living Standard"以后会变成 "Working Draft"吗?

html - Kineticjs 与 Raphaeljs

javascript - 如何在本地机器上没有服务器的情况下在浏览器中运行构建的 vue js 项目?

javascript - 根据条件改变D3散点图上多个点的半径

php - 如何使用 ssp.class.php DataTables 使用 'WHERE' 子句

javascript - 定义回调并立即触发一次的最佳方式?

html - @media 查询不起作用(POSTCSS 生成的 CSS 代码)

javascript - 如何渲染for循环中的数据?

javascript - Twisted 的 Deferred 和 JavaScript 中的 Promise 一样吗?

javascript - 使用 javascript 进行多重下载