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');
    }
}

更多相关文章

  1. 在导航图标css下包装文本。
  2. 轮播图---可以动态添加图片,(封装成一个函数)
  3. javascript高阶函数map和reduce
  4. jQuery插件:如何将元素引用传递给回调函数?
  5. Javascript等待函数的结束,包括node.js的异步MYSQL查询?
  6. JavaScript数组操作函数方法详解
  7. JavaScript:使用函数参数检索javascript对象键
  8. 由浅到深的分析Javascript OO之写类方式之一:构造函数
  9. 如何在Node中创建可重用的函数而不编写样板代码

随机推荐

  1. Android 轮询实现的三种方式
  2. android开源工程
  3. Android系统属性SystemProperties.set/ge
  4. 编译V8静态库 for Android
  5. Android Ble
  6. adb connect 失败时(unable to connect t
  7. Android 从网页中跳转到APP
  8. android 结束进程
  9. Android(安卓)Afinal框架
  10. android view视图的层叠(叠加)