我有两个日期选择器。他们将一些数据传递给同一个函数(onchange
)。
<DatePicker
showTime
format="YYYY-MM-DD HH:mm:ss" placeholder="Start"
onChange={this.onChange()}
/>
<DatePicker
showTime
format="YYYY-MM-DD HH:mm:ss"
placeholder="End"
onChange={this.onChange()}
/>
我需要从它们接收不同的日期值并将其传递给timerChange
,但我只获得一个值。如何获得这两个值?
onChange = (value, dateString) => {
const startDate = new Date(value[0]).getTime() / 1000;
const endDate = new Date(value[1]).getTime() / 1000;
this.setState({
start: startDate,
end: endDate
});
this.props.timer.changeTime(startDate, endDate);
};
答案 0 :(得分:0)
开始日期和结束日期可以有两个不同的ID,您可以使用ID的值来获取日期,如下所示
$(function() {
$("#datepicker1").datepicker();
$("#datepicker2").datepicker();
});
var dateFinder = function() {
$("#datepicker1").datepicker();
$("#datepicker2").datepicker();
console.log("Start Date : " + datepicker1.value);
console.log("Start Date : " + datepicker2.value);
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.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>
</head>
<body>
<p>Start Date: <input type="text" id="datepicker1"></p>
<p>End Date: <input type="text" id="datepicker2"></p>
<button type="submit" onClick="dateFinder()">Submit</button>
</body>
</html>
&#13;