我正在尝试使用Excel Vba从IE的下拉kendolistbox中选择项目 [英] I'm trying to select and item from a dropdown kendolistbox in IE with Excel Vba
问题描述
我找到了从下拉列表中选择固定选项的解决方案. 现在我要做的就是弄清楚如何根据选择来选择项目..
I found a solution to choosing a fixed selection from a dropdown list. Now all I have to do is figure out how to choose an item based on the choices.
以下内容在下拉菜单中选择第一项,但是,我发现使下拉菜单打开"是不必要.
The following chooses the first item in the dropdown, however, I found out that making the dropdown "open" is not necessary.
将 select 参数更改为2可以选择列表中的第二项,依此类推.
Changing the select parameter to 2 chooses the second item in the list etc.
我想尝试使用getElementById
并循环遍历innerText可能是一种方法,因为我不知道其他任何方法.
I suppose trying to use getElementById
and cycling through the innerText may be the way to go, since I don't know any other way.
ie.Document.parentWindow.execScript "$('#drgdTankCrude').data('kendoGrid').dataItem($('#Tank_ID').data('kendoDropDownList').select(1));"
这是网页代码的一部分.
Here a section of the web page code.
<input name="Tank.ID" id="Tank_ID" style="width: 200px; display: none;" type="text" data-role="dropdownlist"></span>
'Lots of other stuff in here for formatting
<div class="k-widget k-grid" id="drgdTankCrude" style="left: 890.32px; top: 93.7px; display: block; position: absolute;" data-role="grid">
<table class="k-selectable" role="grid" style="-ms-touch-action: double-tap-zoom pinch-zoom;" data-role="selectable">
<colgroup><col><col></colgroup>
<thead class="k-grid-header" role="rowgroup">
<tr role="row">
<th class="k-header" scope="col" data-title="Tank" data-index="0" data-field="ID"><span class="k-link">Tank</span></th>
<th class="k-header" scope="col" data-title="Capacity" data-index="1" data-field="Capacity"><span class="k-link">Capacity</span></th>
</tr>
</thead>
<tbody role="rowgroup">
<tr class="k-state-selected" aria-selected="true">
<td>179800</td>
<td>202.06</td></tr>
<tr class="k-alt" aria-selected="false">
<td>179801</td>
<td>202.82</td>
</tr>
</tbody>
</table>
</div>
'Code before dropdown
<tbody role="rowgroup">
<tr>
<td>179800</td>
<td>202.06</td></tr>
<tr class="k-alt">
<td>179801</td>
<td>202.82</td>
</tr>
</tbody>
'Code before dropdown opens
<div class="k-widget k-grid" id="drgdTankCrude" style="left: 890.32px; top: 93.71px; display: none; position: absolute;" data-role="grid">
'Code change after dropdown opens
<div class="k-widget k-grid **k-custom-visible**" id="drgdTankCrude" style="left: 890.32px; top: 93.71px; display: block; position: absolute;" data-role="grid">
'Code change after making a selection
<tbody role="rowgroup">
<tr class="k-state-selected" aria-selected="true">
<td>179800</td> '<<-----This item selected
<td>202.06</td></tr>
<tr class="k-alt" aria-selected="false"> '<<--If selected then unselected
<td>179801</td> 'otherwise ends at k-alt">
<td>202.82</td>
</tr>
</tbody>
推荐答案
在kendoDropDownList中选择第一项的答案.
The answer to selecting the first item in a kendoDropDownList ..
ie.Document.parentWindow.execScript "$('#drgdTankCrude').data('kendoGrid').dataItem($('#Tank_ID').data('kendoDropDownList').select(1));"
这篇关于我正在尝试使用Excel Vba从IE的下拉kendolistbox中选择项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!