我正在尝试通过 Keyboard Maestro 中的 Execute Javascript 宏来选择一个下拉项。该代码用于选择和验证下拉项,但在我使用它的页面中,还有其他下拉应根据选择自动填充。当我手动单击下拉项目时,其他下拉菜单会相应更新。通过我正在使用的javascript,它选择了该项目,但留下了其他下拉菜单。我需要使用纯 javascript 而不是 jquery。有没有人对如何让页面根据 javascript 选择做出反应有任何想法?
// variable to enter into dropdown
var vDropdownInput = (document.kmvar.vZEROInput);
// variable to get the Element by ID
var objSelect = document.getElementById("web-selection_"+document.kmvar.vZEROIndex+"_");
// function to do the work
setSelectedValue(objSelect, vDropdownInput);
// function definition
function setSelectedValue(object, value) {
for (var i = 0; i < object.options.length; i++) {
if (object.options[i].text === value) {
object.options[i].selectedIndex = i;
return;
}
}
// Throw exception if option `value` not found.
var tag = object.nodeName;
var str = value;
return str;
}
编辑:我找到了这个相关的帖子,但我没有得到建议的解决方案。 通过 JavaScript 在 CascadingDropDown 中选择项目并调用更新