1

我正在尝试在 Excel 中为名为 SpectrumLive 的股票交易网站创建 VBA 界面。

我可以在网站上的相关表格中填写要购买的股票数量。但是,当我单击“下订单”按钮时,它会记住我输入的最后一个手动值,而不是 VBA 输入的值。就像我需要引发一个事件或类似的东西来让服务器端注册值。

该字段看起来像一个带有可编辑文本字段的组合框。您实际上可以通过选择组合框控件中的小箭头来选择预定义的值。但是脚本直接将值输入到文本字段中(就像我也可以手动执行一样)。

我一直在研究这个特定的问题很长一段时间,但我已经没有想法了。

我使用的 VBA 是:

theDocument.getElementsByName("ordertype").Item(i).value = "88"

用于将要交易的股票数量设置为 88。

我试图通过以下方式触发 OnChange 事件:

theDocument.getElementsByName("ordertype").Item(i).FireEvent ("onchange")

但没有运气。

页面特定部分的 HTML 代码如下所示:

<div id="MenuMgr_WM_view4_widgetbfcca409xc930x42d5x8d00x04a83ed68e5f_ordertab_amountrow" class="formrow">

<div id="MenuMgr_WM_view4_widgetbfcca409xc930x42d5x8d00x04a83ed68e5f_ordertab_amountrow_error" class="error_field">

<span class="inline amount">

<label class="label" title="Quantity">Quantity:</label>

<div class="amount_type input selector" style="display:none;" name="MenuMgr$WM_view4$widgetbfcca409xc930x42d5x8d00x04a83ed68e5f$ordertab$amountrow$ctl00">

<span id="MenuMgr_WM_view4_widgetbfcca409xc930x42d5x8d00x04a83ed68e5f_ordertab_amountrow_amount" name="MenuMgr$WM_view4$widgetbfcca409xc930x42d5x8d00x04a83ed68e5f$ordertab$amountrow$amount">

<div id="AmountSelectorContainer">

<span id="MenuMgr_WM_view4_widgetbfcca409xc930x42d5x8d00x04a83ed68e5f_ordertab_amountrow_amount_AmountSelectorControl" name="MenuMgr$WM_view4$widgetbfcca409xc930x42d5x8d00x04a83ed68e5f$ordertab$amountrow$amount$AmountSelectorControl">

<div id="AmountSelectorDropDownList" class="left input selector" name="MenuMgr$WM_view4$widgetbfcca409xc930x42d5x8d00x04a83ed68e5f$ordertab$amountrow$amount$AmountSelectorControl$AmountSelectorDropDownList">

**<input class="inp aright" type="text" value="" name="ordertype" title="">**

<div class="btns">

</div>

</span>

</div>

</span>

</span>

<div class="formrow amount_info" style="display: none;"> </div>

即使上面名为“ordertype”的字段中的“值”是“”,SpectrumLive 显示数量为 88(我有 Firebug 向我显示哪个字段代表组合框的文本字段)。

对此的任何帮助将不胜感激!

谢谢,

4

1 回答 1

0
<input class="inp aright" type="text" value="" name="ordertype" title="">

上面的 html 是一个文本框,要设置它的值,您可以使用下面的代码。

 Set i_Order = theDocument.getElementsByName("ordertype")
 i_Order.Value = "88"

或者

 Set i_Amt = theDocument.getelementbyid("AmountSelectorDropDownList")
 set i_Order = i_Amt.NextSibling  '(put a breakpoint here)
 i_Order.Value = "88"

(转到即时窗口并将此文本?i_order.OuterHTML置于调试模式,这将让您知道是否有 ordertype 文本框。如果它不起作用,您可以试试这个set i_Order = i_Amt.NextSibling.NextSibling

此外,我没有看到任何附加到文本框的 javascript 更改事件,无需使用 FireEvent。

于 2013-06-02T01:48:09.283 回答