
上QQ阅读APP看书,第一时间看更新
Adding a date
Most presentations are usually dated, or at least some of the jokes are! We will add a convenient button for the user to add a date to the presentation using the HTML5 input type date, which provides a graphical date picker:
<input type="date" id="selDate" value="2000-01-01"/>
The default value is set in the index.html
page as follows:

The valueAsDate
property of the DateInputElement
class provides the Date
object, which can be added to the text area:
void insertDate(Event event) { DateInputElement datePicker = querySelector("#selDate"); if (datePicker.valueAsDate != null) presEditor.value =presEditor.value + datePicker.valueAsDate.toLocal().toString(); }
In this case, the toLocal
method is used to obtain a string formatted to the month, day, and year format.