繁体   English   中英

vbscript捕获html选择选项标记中的文本

[英]vbscript capture text in the html select option tag

我已经查看了所有其他问题,加上许多在互联网上搜索,找不到任何符合我情况的内容。

我有一个在VBScript for IBM Personal Communications(PCOMM)中开发的宏。 我的老板要我转换它,以便可以在Macro Express Pro(ME)中使用。 ME是一个WYSIWYG(所见即所得)编辑器,它具有预设功能并允许JScript,VBScript和HTA的外部脚本编写。

PCOMM宏大约有1000行纯VBScript,所以保持这种方式才有意义,但ME不允许PCOMM做的一些事情,因此需要进行一些修改。

一个修改是已经存在一个Internet Explorer(IE)的全局实例,因此宏被设计为使用该实例。 我正试图获得下拉框的选定选项,但我尝试过的所有内容都不成功。

这是HTML代码:

<select name="ctl00$cphContent$ddlWorkQueue" onchange="javascript:setTimeout('__doPostBack(\'ctl00$cphContent$ddlWorkQueue\',\'\')', 0)" id="ctl00_cphContent_ddlWorkQueue" class="ddlbox">
    <option selected="selected" value="5422">605</option>
    <option value="5419">ACCUM</option>
    <option value="5418">CORRESPONDENCE</option>
    <option value="5415">FEKEY</option>
    <option value="5416">NKPORTAL</option>
    <option value="5420">PROVIDER</option>
    <option value="5423">EDITS</option>
    <option value="5421">TRACR</option>
    <option value="5417">WAND</option> 
</select>

如您所见,选择“605”。 我希望能够在消息框中显示“605”。 这是VBScript:

'This subroutine checks to see if the selected queue matches the ini value if it does not it updates the ini value
Sub SetQueue
    Dim Selection

    'Commented out by previous developer.  We do not want to create a new instance of Internet Explorer.  We want to use the existing instance...
    'Set objIE = CreateObject("InternetExplorer.Application")

    Selection = Document.getElementById("ctl00_cphContent_ddlWorkQueue").selectedIndex
    MsgBox "Selection: " & Selection
End Sub

希望有人可以给我一些帮助,并指出我正确的方向。 我运行宏时得到的只是“选择:”。

任何这些方法应该工作:

' Method 1 - Get the current HTML displayed within the <select> element:
MsgBox Document.getElementById("ctl00_cphContent_ddlWorkQueue").innerHTML

' Method 2 - Get the current text displayed within the <select> element:
MsgBox Document.getElementById("ctl00_cphContent_ddlWorkQueue").innerText

' Method 3 - Use the selected index to look up the selected option:
Set e = Document.getElementById("ctl00_cphContent_ddlWorkQueue")
MsgBox e.Options(e.selectedIndex).Text

' Method 4 - Loop through all options looking for the selected one:
For Each o In Document.getElementById("ctl00_cphContent_ddlWorkQueue").Options
    If o.Selected Then MsgBox o.Text
Next

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM