我可以使用onBlur事件对TextBox进行日期检查吗?
16lz
2021-01-22
I want to do a Date Check on a TextBox with a onBlur event. I am not sure how to check the textbox in javascript on the aspx side. This is what I have so far
我想在带有onBlur事件的TextBox上进行日期检查。我不知道如何在aspx端检查javascript中的文本框。这就是我到目前为止所拥有的
TodayDate= new Date();
function checkEnteredDate() {
if (document.getElementById('txtDate') > TodayDate) {
alert("You cannot select a date later than today.");
document.getElementById(TodayDate);
}
}
This is already a javascript function, I just cannot get the value in the textbox for a comparison. Any suggestions?
这已经是一个javascript函数,我只是无法在文本框中获取值进行比较。有什么建议?
5 个解决方案
#1
You could try passing the "this" to the function:
您可以尝试将“this”传递给函数:
<asp:TextBox ID="Text1" onblur="CheckEnteredDate(this);" runat="server" />
Edit: Here's how the javascript function would use that (roughly):
编辑:以下是javascript函数将如何使用(粗略地):
function CheckEnteredDate(passed) {
if (new Date(passed.value) > new Date()) {
alert('Date greater than today');
}
}
更多相关文章
- 在导航图标css下包装文本。
- 轮播图---可以动态添加图片,(封装成一个函数)
- javascript高阶函数map和reduce
- jQuery插件:如何将元素引用传递给回调函数?
- Javascript等待函数的结束,包括node.js的异步MYSQL查询?
- JavaScript数组操作函数方法详解
- JavaScript:使用函数参数检索javascript对象键
- 由浅到深的分析Javascript OO之写类方式之一:构造函数
- 如何在Node中创建可重用的函数而不编写样板代码