这是我的Javascript代码。如果datepicker为空,我需要为datepicker添加验证;日期不能为空"; 函数 isDateSelected(){ var today=新日期(); var inputDate=新日期(document.myForm.Date.value); 如果(inputDate.value==“”){ 返回false; }否则如果(输入日期>今天){ 返回false; }否则{ 返回true; }}左{ 浮动:左; 宽度:200px; 文本对齐:居中;}。右{ 浮动:对; 宽度:100px; 页边距顶部:20px;}.center{ 保证金:自动; 宽度:300px;} .labelClass{ 浮动:左; 宽度:150px; 页边空白顶部:20px;}。空格{填充:0px 0px 0px 30px;} .分隔器{ 宽度:50px; 高度:自动; 显示:内联块;}。按钮{位置:相对;左侧:0%;页边距顶部:10%;} 衍生工具交易特别报告 输入详细信息 起始日期:客户(除 衍生金融工具(现金) 迄今为止: -所有客户-JHP-NAVLP JOHAMBRO JOHCM法律及合规部 TPA 姓名:
如下更改您的函数:这是我的Javascript代码。如果datepicker为空,我需要为datepicker添加验证;日期不能为空"; 函数 isDateSelected(){ var today=新日期(); var inputDate=新日期(document.myForm.Date.value); 如果(inputDate.value==“”){ 返回false; }否则如果(输入日期>今天){ 返回false; }否则{ 返回true; }}左{ 浮动:左; 宽度:200px; 文本对齐:居中;}。右{ 浮动:对; 宽度:100px; 页边距顶部:20px;}.center{ 保证金:自动; 宽度:300px;} .labelClass{ 浮动:左; 宽度:150px; 页边空白顶部:20px;}。空格{填充:0px 0px 0px 30px;} .分隔器{ 宽度:50px; 高度:自动; 显示:内联块;}。按钮{位置:相对;左侧:0%;页边距顶部:10%;} 衍生工具交易特别报告 输入详细信息 起始日期:客户(除 衍生金融工具(现金) 迄今为止: -所有客户-JHP-NAVLP JOHAMBRO JOHCM法律及合规部 TPA 姓名:,javascript,html,Javascript,Html,如下更改您的函数: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <script type="text/javascript"> function isDateSelected(){ var today =new Date(); var inputDate = new Date(document.myFo
<html> <head> <meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1"> <script type="text/javascript"> function
isDateSelected(){
var today =new Date();
var inputDate = new Date(document.myForm.date.value);
if (inputDate.value == " "){
return false;
} else if (inputDate > today) {
return false;
} else {
return true;
} } </script> <style type="text/css"> .left {
float: left;
width: 200px;
text-align: center; } .right {
float: right;
width: 100px;
margin-top: 20px; } .center {
margin: auto;
width: 300px; }
.labelClass{
float: left;
width: 150px;
margin-top: 20px; } .space{ padding: 0px 0px 0px 30px;}
.divider{
width:50px;
height:auto;
display:inline-block; } .button{ position:relative; left: 0%; margin-top:10%; }
</style> </head> <body style="background-color:#D3D3D3"> <form
id="date" name="myForm" action="demo_form.asp" onsubmit="return
isDateSelected();">
<div> <h1 style="padding: 10px; color: black; background-color:
#D3D3D3; border: #82CAFF 2px solid"><center>Derivative Trade Report Adhoc</center></h1> </div>
<fieldset style="height: 250px;" style="margin-top:50px;">
<legend>Input Details</legend>
<table cellspacing="5" border="0" style="padding-left: 120px;">
<tr>
<td> <span class="labelClass"> From Date:</span> <input type="date"
class="labelClass" > </td> <td class="space">Clients(For other than
Derivative Cash)</td> </tr> <tr> <td> <span class="labelClass">
To Date:</span> <input type="date" class="labelClass"> </td>
<td class="space" rowspan="2">
<select autofocus="true" multiple="multiple" style="width: 250px;">
<option value="All Clients">-ALL Clients-</option> <option
value="JHP-NAVLLP">JHP-NAVLLP</option> <option
value="JOHAMBRO">JOHAMBRO</option> <option
value="JOHCM">JOHCM</option> <option value="L&C">L&C</option>
</select> </td> </tr> <tr> <td> <span class="labelClass"> TPA
Name:</span> <input type="text" class="labelClass"> </td> </tr> <tr>
</tr> <tr> </tr> </table> </fieldset>
<div style="padding: 20px;text-align:center;border: #82CAFF 2px
solid;margin-top: 5%" class="button" > <input type="submit" name="Run
Report" value="Create Report"></input> </div>
</form> </body> </html> </html
欢迎来到堆栈溢出!请阅读,特别是因为您希望显示警报,所以只需在函数isDateSelected()中的返回false之前添加它,执行警报(“日期不应为空”)!!问题在哪里。
isDateSelected(){
var today =new Date();
var inputDate = new Date(document.myForm.date.value);
if (inputDate.value == ""){
alert("date cannot be empty");
return false;
} else if (inputDate > today) {
return false;
} else {
return true;
}
}