javascript - 在 IF 语句中使用 VB 中的 'Day' 函数来更改日期并根据工作日发送表格

标签 javascript html vb.net

我正在编写一个 Windows 应用程序,它可以浏览 WebBrowser 控件并根据某些条件自动填写表单。在一些特定的表单上,会提取一些日期,以便根据该条件检索某些信息。问题是,在星期一,开始日期必须是前一周的星期五。对于所有其他日期(周二至周五),开始日期为前一天。我正在尝试使用 If 语句来解决此问题,但是当我运行表单时,它没有填写正确的日期。

这是我正在使用的:

Public Class Form1
    Inherits Form

    Dim otherdays = Format(Now.AddDays(-1), "M/d/yyyy")
    Dim mondays = Format(Now.AddDays(-3), "M/d/yyyy")
    Dim current = Format(Now, "M/d/yyyy")

    Private Sub approval1()
        WebBrowser1.Document.GetElementById("txtDate").SetAttribute("Value", mondays)
        WebBrowser1.Document.GetElementById("Search").InvokeMember("click")
    End Sub

    Private Sub approval2()
        WebBrowser1.Document.GetElementById("txtDate").SetAttribute("Value", otherdays)
        WebBrowser1.Document.GetElementById("Search").InvokeMember("click")
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If ComboBox1.SelectedItem = "IM Approval" Then
            WebBrowser1.Navigate("https:")
            WaitForPageLoad()

            'This is the part that does not work:
            If Now.Day = Day.Monday Then
                approval1()
                WaitForPageLoad()
                WebBrowser1.Navigate("javascript: ('','')")
            Else
                approval2()
                WaitForPageLoad()
                WebBrowser1.Navigate("javascript: ('','')")
            End If
        End If
    End Sub

通过 Javascript 进行浏览的 Web 浏览器不是问题。填写日期是唯一的问题。

最佳答案

您对星期几的检查不起作用的原因是您正在检查月份的哪一天。这是 for 类的更简单版本,其中 if 语句已更正。

Public Class Form1
    Inherits Form

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If ComboBox1.SelectedItem = "IM Approval" Then
            WebBrowser1.Navigate("https:")
            WaitForPageLoad()

            Dim adjust As Integer = If(Now.DayOfWeek = DayOfWeek.Monday, -3, -1)
            WebBrowser1.Document.GetElementById("txtDate").SetAttribute("Value", Format(Now.AddDays(adjust), "M/d/yyyy"))
            WebBrowser1.Document.GetElementById("Search").InvokeMember("click")

            WaitForPageLoad()
            WebBrowser1.Navigate("javascript: ('','')")
        End If
    End Sub
End Class 

关于javascript - 在 IF 语句中使用 VB 中的 'Day' 函数来更改日期并根据工作日发送表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28434461/

相关文章:

html - 在 css 中使用 % 调整图像大小

vb.net - 将 XNA + VB.Net 游戏转换为 MonoGame

javascript - 字符串中的单个反斜杠

javascript - 如何使用 angular.js 发布多个请求

JavaScript 验证不会停止提交到 php 脚本

vb.net - 您如何在自己的类(class)中处理类(class)中提出的事件?

asp.net - 删除字符串中的双换行符

javascript - 我们总是有 session[] 变量,那么 HTML5 的 code.SessionStorage 带来了什么新东西呢?

html - WebKit 和 Mozilla 遵循的真实 CSS3 动画规范在哪里?

javascript - 根据自定义属性过滤 SELECT 选项