如何通过jQuery在datetime local上获取datetime
我的表单上有datetime本地html控件,我需要通过jQuery动态获取它的日期和时间。我怎么做如何通过jQuery在datetime local上获取datetime,jquery,html,Jquery,Html,我的表单上有datetime本地html控件,我需要通过jQuery动态获取它的日期和时间。我怎么做 <input type="datetime-local" id="publishDate" /> 但它不起作用。检查此代码并给出初始值记住同时给出日期和时间值 <h3>A demonstration of how to access a Local Datetime field</h3> <input type="datetime-local" id
<input type="datetime-local" id="publishDate" />
但它不起作用。检查此代码并给出初始值记住同时给出日期和时间值强>
<h3>A demonstration of how to access a Local Datetime field</h3>
<input type="datetime-local" id="publishDate" value="2014-11-16T15:25:33">
<p>Click the button to get the local date and time of the datetime field.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("publishDate").value;
document.getElementById("demo").innerHTML = x;
}
</script>
如何访问本地日期时间字段的演示
单击按钮以获取datetime字段的本地日期和时间
试试看
函数myFunction(){
var x=document.getElementById(“publishDate”).value;
document.getElementById(“demo”).innerHTML=x;
}
仅当您选择了完整的日期和时间时,才会获取值。其他任何东西它都不会返回任何东西。在创建代码时,只需给它一个初始值。是的,这就成功了。效果很好,但它没有强调我的代码不起作用的原因(即,我没有填写完整的日期和时间)
<h3>A demonstration of how to access a Local Datetime field</h3>
<input type="datetime-local" id="publishDate" value="2014-11-16T15:25:33">
<p>Click the button to get the local date and time of the datetime field.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("publishDate").value;
document.getElementById("demo").innerHTML = x;
}
</script>