大家好,我想问一下,如何通过webbrowser 给打开的网页中的 文件选择框 type=file 赋值呢?

解决方案 »

  1.   

    去看我的BLOG.上面一般的操作代码都全的...深的不会
      

  2.   

    实际上需要你具体分析要操作的URL......看了也不是很清楚可以把URL留下.....我试试
      

  3.   

    出于安全的考虑,file元素被设定为不能通过属性或方法设置内容.因此只能找些变通的方法来实现,比如 SendKeys下面的例子需要在窗体上放一个webbrowser,一个timer。
    Option Explicit
    Private WithEvents fl As HTMLInputElementPrivate Sub fl_onfocus()
        SendKeys ("c:{\}test.htm")
    End SubPrivate Sub Form_Load()
        WebBrowser1.Navigate2 "c:\test.htm"
    End SubPrivate Sub Timer1_Timer()
        Timer1.Enabled = False
        If Not fl Is Nothing Then
            fl.focus
        End If
    End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        Dim oDoc As HTMLDocument
        Set oDoc = pDisp.Document
        
        If oDoc Is Nothing Then Exit Sub
        Set fl = oDoc.getElementById("fl")
        
        Timer1.Interval = 10
        Timer1.Enabled = True
    End Sub
      

  4.   

    对了,还需要引用Microsoft HTML Object Library
      

  5.   

    赋值也是假的不过我也这么做过....嘿嘿用wscript的sendkeys也是可以的。不过这也就是webbrowser要是到网页里,权限太小。
      

  6.   

    我想的办法,将 filetype 的上一个文本框获取焦点,再 sendkeys "{tab}" ,但是好象必须程序要得到焦点才行