eag*_*i22 0 javascript debugging asp.net-mvc-4
我一直得到"期待;" 我定义的三个int变量(月,日,年)的错误:
<script type="text/javascript">
function validateDateFormat(input)
{
var values = input.value.split("/");
int month = parseInt(values[0]);
int day = parseInt(values[1]);
int year = parseInt(values[2]);
if ((month < 1 || month > 12))
{
alert("Month value: "+ month + " is not a valid month using MM/DD/YYYY format");
input.value = "";
return;
}
if ((String.valueOf(year).length() != 4))
{
alert("Year value: "+ year + " is not a valid year using MM/DD/YYYY format");
input.value = "";
return;
}
if(day < 1 || day > daysInMonth(month, year))
{
alert("Day value: "+ day + " is not a valid day for the month with value: " + month + " using MM/DD/YYYY format");
input.value = "";
return;
}
};
Run Code Online (Sandbox Code Playgroud)
....
当我尝试运行页面时,FireFox中的调试器抛出:
SyntaxError:missing; 在声明之前
我不明白问题是什么.即使我这样做,int month = 0作为第一行,我仍然得到相同的错误.我在Asp.net MVC 4上使用Razor
您没有像int在javascript中那样声明变量.
更改
int month = parseInt(values[0]);
Run Code Online (Sandbox Code Playgroud)
至
var month = parseInt(values[0]);
Run Code Online (Sandbox Code Playgroud)
(当然也为以下两行做了)
如果你真的想要键入变量,你可以看一下TypeScript,但我强烈建议你先深入了解惯用的JS.
| 归档时间: |
|
| 查看次数: |
30 次 |
| 最近记录: |