JavaScript验证的跨浏览器问题
Cross Browser issue with JavaScript Validation
所以我让我的代码在Chrome中工作得很好。在FF中,我得到了带有日期的前两个警报,它们的格式正确,但如果选择了过去的日期,则不会抛出第三个警报。在IE中,我得到所有三个警报,但即使我选择了一个未来的日期。正如我所提到的,Chrome可以正常工作,所以如果有人能提供一些见解,使它在所有这些工作,那将是伟大的。
function check()
{
var selecteddate = document.form1.selectmonth.value + "-" + document.form1.selectday.value + "-" + document.form1.selectyear.value;
var d = new Date();
var today = (d.getMonth()+1) + "-" + d.getDate() + "-" + d.getFullYear();
// I'd then make some alerts and it'd return the selected date and today with no problem
alert(selecteddate);
alert(today)
//Now for the if statement is where it just stops working. I think maybe I'm doing
//something wrong just solely in the if statement.
if(new Date(selecteddate) < new Date(today))
{
alert("Past dates are not valid");
return false;
}
}
</script>
您的日期对FF无效,使用"/"
代替selecteddate
和today
的"-"
。
或者直接用
if(selecteddate < today)
代替
if(new Date(selecteddate) < new Date(today))
相关文章:
- 跨浏览器问题:如何调试我的网站'在windows PC的safari上的行为
- DOM 操作、向后兼容性和跨浏览器问题
- 这是HTML5和javascript的浏览器问题吗
- Javascript Array 跨浏览器问题
- 斯克罗尔移动浏览器问题
- 当单击 shift + 鼠标左键单击时,Internet Explorer 浏览器问题 ,文本会自动突出显示
- Javascript跨浏览器问题
- jquery AJAX 获取请求跨浏览器问题
- 脚本标记的跨浏览器问题
- PhoneGap外部浏览器问题
- 使用jQuery Mobile时出现跨浏览器问题
- 在发布到服务器之前进行一些客户端验证 - 浏览器问题
- onLoad中未加载JavaScript(Android webView浏览器问题)
- DIV滚动器的跨浏览器问题
- 浏览器问题:分支选择下拉菜单在IE 7或8中不支持
- 表单提交的跨浏览器问题
- Internet Explorer浏览器问题:浏览器不提交POST数据与Ajax请求,服务器/客户端挂起
- 检查用户名是否存在-跨浏览器问题!建议
- JavaScript验证的跨浏览器问题
- Chrome浏览器问题:“加载资源:net::ERR_CONNECTION_TIMED_OUT”失败