我是jquery新手,我写了下面的代码
<h1>Type your comment below </h1>
<h2>TextBox value : <label id="msg"></label>-<label id="date"></label></h2>
<div style="padding:16px;">
TextBox : <input type="text" value="" placeholder="Type Your Comment"></input>
</div>
<button id="Get">Get TextBox Value</button>
var fullDate = new Date();
$("button").click(function(){
$('#msg').html($('input:text').val());
});
当标签有id="date"
时,按下提交按钮时如何显示日期?
当用户按下提交按钮时我想显示
"User entered Textbox Value - Date with time"
最佳答案
只需使用适当的 CSS 选择器即可添加消息和日期。引用下面的代码:
$("button").click(function() {
var msg = $('input:text').val();
var fullDate = new Date();
$('#msg').html(msg);
$('#date').html(toLocal(fullDate));
});
function toJSONLocal (date) {
var local = new Date(date);
local.setMinutes(date.getMinutes() - date.getTimezoneOffset());
return local.toJSON().slice(0, 10);
}
function toLocal (date) {
var local = new Date(date);
local.setMinutes(date.getMinutes() - date.getTimezoneOffset());
return local.toJSON().replace('T', ' ').slice(0, 19);
}
注意:toJSONLocal、toLocal用于格式化日期。
关于javascript - Jquery:如何用文本框值显示日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38073828/