gpt4 book ai didi

Javascript:数据验证表单

转载 作者:行者123 更新时间:2023-11-28 00:19:34 25 4
gpt4 key购买 nike

我有一个用 Javascript 制作的数据验证程序,它运行良好,它基本上显示了特定日期的额外信息,例如,它是哪一天,以及其他信息。

我的问题是我不知道如何放入 HTML 标签。

这也是我的任务的屏幕截图: enter image description here

var canvas;
canvas = openGraphics();
var day;
day=prompt( "Please enter your day of birth");
var month;
month = prompt( "Please enter your month of birth");
var year;
year = prompt( "Please enter your year of birth");
var date;
date = new Date( year, month-1,day);
if(true){
if(date.getFullYear()== year )
{
}
if( date.getMonth()== month-1 )
{
}
if( date.getDate()== day )
{
}
else{
alert( "Invalid Date" );
}
}
canvas.setFont( "Palatino Linotype", "24px", Font.PLAIN );
canvas.setColor("blue");
canvas.drawString( "Full DOB:", 10, 10 );
canvas.drawString( date, 100, 10 );
canvas.paint();

到目前为止,我尝试的 HTML 都是错误的,我需要有人向我展示如何将上面的代码实现为 html 格式:

<html>
<head>
<title>
Date Validation
</title>
<script>
function checkdate(){

var year = document.getElementById('year').value;
var month = document.getElementById('month').value;
var day = document.getElementById('day').value;

var date = new Date( year, month-1,day);

if(true)

{

if(date.getFullYear()== year )
if( date.getMonth()== month-1 )
if( date.getDate()== day )

}

else{
alert( "Invalid Date" );
}
</script>
<body>
<h1>Data Validation</h1>
<p> This page will be used to provide information on the specific date that you enter below. </p>
<form>
Day:
<input type = "text" input id="day" onchange = "checkdate();>
</form>
<form>
Month:
<input type = "text" input id="month" onchange = "checkdate();>
</form>
<form>
Year:
<input type = "text" input id="year" onchange = "checkdate();">
</form>
<form>
<input type="submit" value="Validate Date">
</form>
</body>
</html>

最佳答案

您需要关闭引号,并从行中间删除input。而不是

<form>
Day:
<input type = "text" input id="day" onchange = "checkdate();>
</form>
<form>
Month:
<input type = "text" input id="month" onchange = "checkdate();>
</form>
<form>
Year:
<input type = "text" input id="year" onchange = "checkdate();">
</form>

使用

<form>
Day:
<input type="text" id="day" onchange="checkdate()">
</form>
<form>
Month:
<input type="text" id="month" onchange="checkdate()">
</form>
<form>
Year:
<input type="text" id="year" onchange="checkdate()">
</form>

另外,避免使用像 onchange="checkdate();"这样的分号是一个好习惯

关于Javascript:数据验证表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30155467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com