【问题标题】:VBA Excel run javascript form eventVBA Excel运行javascript表单事件
【发布时间】:2016-05-01 05:44:57
【问题描述】:

我已经尝试通过 id 获取元素,但是 html 不包含它。如下所示,这是我试图自动更改的下拉脚本。它将使用

更改名称

appIE.Document.getElementById("supervisor").Value = "Sup_name"

但是,它不会触发生成人员列表的事件。

表格顶部还包括<form id='filterform' action="javascript:void(0);">

下面是包含我需要调用的函数的JavaScript。

<script type="text/javascript">

    $(function() {
        $('#supervisor').change(function() {
            document.getElementById('results').innerHTML = '<img src="/img/busy.gif" />';
            var str = $('#filterform').serializeArray();
            $.ajax({
                url: 'ajax.php?p=agentrosters&mode=1&field=supervisor',
                type: 'POST',
                data: str,
                success: function(j) {
                    //alert(j);
                    document.getElementById('results').innerHTML = j;
                    document.getElementById('lastsearch').value = 'supervisor';
                    resetscript('supervisor');
                },
                failure: function() {
                    document.getElementById('results').innerHTML = 'There has been an error, please try again';
                    resetscript('null');
                }
            })
        })
    })

</script>

关于如何让它发挥作用的任何想法?

【问题讨论】:

  • 试试appIE.Document.getElementById("supervisor").change()appIE.Document.getElementById("supervisor").Firevent("onchange")
  • 我都试过了,但都没有奏效。第一个给了我一个错误“expecting ="
  • 错字 - .Firevent("onchange") >> .FireEvent("onchange")
  • 即使纠正了错字,它仍然没有正确触发 JavaScript 事件。

标签: javascript jquery html excel vba


【解决方案1】:

如果元素是表单的一部分,您可以提交表单,或者您可以在元素本身上使用 onchange 事件。所以你可能想改变

appIE.Document.getElementById("supervisor").Value = "Sup_name"

With appIE.document.getElementById("supervisor") .Value = "Sup_name" .onchange End with

如果它是表单的一部分,请将“.onchange”更改为 ".parentElement.Submit"

这对我有用。

【讨论】:

猜你喜欢
  • 2018-01-27
  • 2013-11-06
  • 2020-09-13
  • 1970-01-01
  • 1970-01-01
  • 2018-02-10
  • 2022-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多