vbscript捕获html选项标签中的文本 [英] vbscript capture text in the html select option tag

查看:107
本文介绍了vbscript捕获html选项标签中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了所有其他问题,以及通过互联网进行的许多搜索,但无法找到符合我的情况的任何内容。



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


$ b PCOMM宏是大约1000行纯VBScript,所以只有这样才行,但ME不允许PCOMM做某些事情,所以需要做一些修改。



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



这里是HTML代码:

 < select name =ctl00 $ cphContent $ ddlWorkQueueonchange =javascript:setTimeout('__ doPostBack(\'ctl00 $ cphContent $ ddlWorkQueue\\ \\',''')',0)id =ctl00_cphContent_ddlWorkQueueclass =ddlbox> 
< option selected =selectedvalue =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的代码:

 '该子例程检查所选队列是否与ini值匹配,如果不更新ini值
Sub SetQueue
Dim Selection

'由以前的开发者注释掉。我们不想创建Internet Explorer的新实例。我们想使用现有的实例...
'Set objIE = CreateObject(InternetExplorer.Application)

Selection = Document.getElementById(ctl00_cphContent_ddlWorkQueue)。selectedIndex
MsgBox选择:&选择
结束小组

希望有人能为我提供一些帮助,并指向正确的方向。我在运行宏时得到的所有内容都是Selection:。

 '方法1  - 获取当前显示在< select>元素:
MsgBox Document.getElementById(ctl00_cphContent_ddlWorkQueue)。innerHTML

'方法2 - 获取当前显示在< select>元素:
MsgBox Document.getElementById(ctl00_cphContent_ddlWorkQueue)。innerText

'方法3 - 使用选定的索引查找选定的选项:
Set e = Document.getElementById (ctl00_cphContent_ddlWorkQueue)
MsgBox e.Options(e.selectedIndex).Text

'方法4 - 遍历所有选项以查找所选选项:
For Each o in Document.getElementById(ctl00_cphContent_ddlWorkQueue)。Options
如果o.Selected Then MsgBox o.Text
Next


I've looked through all other questions, plus many searches over the internet, and cannot find anything that works with my situation.

I have a macro that was developed in VBScript for IBM Personal Communications (PCOMM). My bosses want me to convert it so it can be used in Macro Express Pro (ME). ME is a WYSIWYG (what you see is what you get) editor that has preset functions and allows for external scripting of JScript, VBScript, and HTA.

The PCOMM macro is about 1000 lines of pure VBScript, so it only makes sense to keep it that way, however ME doesn't allow some things that PCOMM does, so some modifications need to be made.

One modification is there already is one global instance of Internet Explorer (IE), so the macro has been designed to use that instance. I'm trying to get the selected option of a drop down box, but everything I've tried has been unsuccessful.

Here's the HTML code:

<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>

As you can see, "605" is selected. I want to be able to display "605" in a message box. Here's the VBScript for this:

'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

Hopefully someone can offer me some assistance and point me in the right direction. All I get when I run the macro is "Selection: ".

解决方案

Any of these methods should work:

' 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

这篇关于vbscript捕获html选项标签中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆