我正在使用jQuery UI的datepicker
来获取完整的日期和日期。但现在我想在日历上只需点击一下即可。这是我的示例代码:
<script>
$(function(){
var pickerOpts1 = {
dateFormat: "yy-mm-dd"
};
var pickerOpts2 = {
dateFormat: "DD"
};
$("#datepicker1").datepicker(pickerOpts1);
$("#datepicker2").datepicker(pickerOpts2);
});
</script>
字段很简单:
<form method="get" action="check.php">
<p>date: <input type="text" name="dateH" id="datepicker1" /></p>
<p>day: <input type="text" name="dayD" id="datepicker2" /></p>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
非常感谢任何和所有帮助!
答案 0 :(得分:0)
以下是一个可以帮助您的示例:
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(function() {
$('#datepicker1').datepicker({
onSelect: function(date){
var dayNames = ["Sunday","Monday","Tuesday","Wednesday","Thursday", "Friday","Saturday"];
var d=new Date(date).getDay();
$('#datepicker2').val(dayNames[d]);
},
dateFormat:'yy-mm-dd'
})
});
</script>
<form method="get" action="check.php">
<p>date: <input type="text" name="dateH" id="datepicker1" /></p>
<p>day: <input type="text" name="dayD" id="datepicker2" /></p>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
&#13;
答案 1 :(得分:0)
您可以使用解决方案https://jsfiddle.net/0g4runLb/
$(function(){
var pickerOpts1 = {
dateFormat: "yy-mm-dd",
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate');
$('#datepicker2').val($.datepicker.formatDate('DD', date));
}
};
$("#datepicker1").datepicker(pickerOpts1);
});
&#13;
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<form method="get" action="check.php">
<p>date: <input type="text" name="dateH" id="datepicker1" /></p>
<p>day: <input type="text" name="dayD" id="datepicker2" /></p>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
&#13;
希望这会对你有所帮助。