gpt4 book ai didi

javascript - 使用VBA执行javascript函数

转载 作者:行者123 更新时间:2023-12-02 23:40:45 24 4
gpt4 key购买 nike

我尝试使用 VBA 执行 JavaScript 函数,但没有成功。

我在列表框中选择一个项目。

我的目标:选择项目后刷新结果。

VBA:

IEdoc_NEW2.getElementById("native_dropdown_selected_size_name").selectedIndex = 1
Call IEdoc_NEW2.parentWindow.execScript("dummySubmitButton()", "JavaScript")

HTML:

<select name="dropdown_selected_size_name" tabindex="-1" class="a-native-dropdown" id="native_dropdown_selected_size_name" autocomplete="off" data-a-touch-header="Taille">
<option id="native_size_name_-1" value="-1" selected="" data-a-id="size_name_-1">Sélectionner</option>
<option class="dropdownAvailable" id="native_size_name_0" value="0,B07DHJZSB3" data-a-id="size_name_0" data-a-html-content="S" data-a-css-class="dropdownAvailable">
S </option>
<option class="dropdownUnavailable" id="native_size_name_1" value="1,B07DHKZM7P" data-a-id="size_name_1" data-a-html-content="M" data-a-css-class="dropdownUnavailable">
M
</option>
<option class="dropdownUnavailable" id="native_size_name_2" value="2,B07DHK697N" data-a-id="size_name_2" data-a-html-content="L" data-a-css-class="dropdownUnavailable">
L
</option>
</select>

JavaScript:

if (typeof(TwisterNonJs) == 'undefined') {
window.TwisterNonJs = {};
TwisterNonJs.handleDropDown = [];
}
TwisterNonJs.handleDropDown[1] = function() {
var twisterUpdateButton = "submit.twisterUpdateButton_1"
document.getElementById("dummySubmitButton").setAttribute("name", twisterUpdateButton);
document.forms['twister'].submit();
};
document.getElementById("native_dropdown_selected_size_name").onchange = function() {
TwisterNonJs.handleDropDown[1]();
};

但这不起作用。

最佳答案

尝试 onchange fireEvent

IEdoc_NEW2.getElementById("native_dropdown_selected_size_name").FireEvent "onchange"

您还可以尝试添加事件然后触发它

Dim evt As Object
Set evt = .document.createEvent("HTMLEvents")
evt.initEvent "change", True, False

IEdoc_NEW2.querySelector("#native_dropdown_selected_size_name").dispatchEvent evt

关于javascript - 使用VBA执行javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56090916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com