如何使用vbscript更改所选的选项值?

时间:2013-07-29 19:50:01

标签: vbscript

网页上有一个下拉框,代码为:

<select 
name="ctl00$ctl05$ddlCurrency" 
id="ctl00_ctl05_ddlCurrency" 
class="ddlCurrency" 
style="font-size:x-small;width: 55px; background-color: #EDEEEF;">
    <option value="AUD">AUD</option>
    <option value="EUR">EUR</option>
    <option value="GBP" selected="selected">GBP</option>
    <option value="USD">USD</option>
</select>

请告诉我如何更改所选的选项值&#34; GBP&#34;重视&#34; USD&#34;使用vbscript的IE窗口中的下拉框?

谢谢,

Pers2012

1 个答案:

答案 0 :(得分:1)

试试这个:

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://www.example.com/"
While ie.Busy : WScript.Sleep 100 : Wend

For Each opt In ie.document.getElementById("ctl00_ctl05_ddlCurrency").Options
  If opt.Value = "USD" Then
    opt.Selected = True
  Else
    opt.Selected = False
  End If
Next