Javascript 清除IE中的下拉列表
我正在尝试清除一个带有子项的类型下拉列表,jqueryempty命令适用于Chrome,我假设其他浏览器都有,但internetexplorer没有 我试过这个Javascript 清除IE中的下拉列表,javascript,jquery,drop-down-menu,Javascript,Jquery,Drop Down Menu,我正在尝试清除一个带有子项的类型下拉列表,jqueryempty命令适用于Chrome,我假设其他浏览器都有,但internetexplorer没有 我试过这个 document.getElementById("dropdown").length = 0; 或 但是回来了 document.getElementById(...)' is null or not an object 似乎没有任何效果 不确定是否可以对JQuery变量使用纯JavaScript方法 有没有可靠的方法可以清除In
document.getElementById("dropdown").length = 0;
或
但是回来了
document.getElementById(...)' is null or not an object
似乎没有任何效果
不确定是否可以对JQuery变量使用纯JavaScript方法
有没有可靠的方法可以清除Internet Explorer中的元素
HTML很混乱,因为它是从SharePoint中的ASP生成的,但下面是浏览器和javascript读取的相关输出
我使用的是来自GoogleAPI的jQuery1.11.3
和Internet Explorer 11
<tr>
<td nowrap="true" valign="top" width="190px" class="ms-formlabel"><h3 class="ms-standardheader">
<nobr>Interaction Contact</nobr>
</h3></td>
<td valign="top" class="ms-formbody">
<!-- FieldName="Interaction Contact"
FieldInternalName="Interaction_x0020_Contact"
FieldType="SPFieldLookup"
-->
<span dir="none"><select name="ctl00$m$g_d04d1ad3_87fc_4751_9c85_4974c40486ca$ctl00$ctl05$ctl07$ctl00$ctl00$ctl04$ctl00$Lookup" id="ctl00_m_g_d04d1ad3_87fc_4751_9c85_4974c40486ca_ctl00_ctl05_ctl07_ctl00_ctl00_ctl04_ctl00_Lookup" title="Interaction Contact">
<option selected="selected" value="0">(None)</option>
<option value="15788"> John doe , john-doe@mail.net</option>
<option value="15788"> John doe , john-doe@mail.net</option>
<!-- lots of <option> elements that needs to be cleared -->
</select><br></span>
</td>
</tr>
在jquery中,您可以通过以下方式跨浏览器清除它:
$("#dropdown").empty()
尝试:
要使用jQuery执行此操作,请执行以下操作:
$('#dropdown').empty();
试试$dropdown.html或$dropdown。empty@Balachandran返回html不是函数。innerHtml=运行,但不清除列表。同时发布html。我们讨论的IE和jQuery的版本是什么?用这个信息更新了这个问题只是为了检查。。您正在使用id ctl00_m_g_d04d1ad3_87fc_4751_9c85_4974c40486ca_ctl00_ctl05_ctl07_ctl00_ctl00_ctl04_ctl00_Lookup not下拉列表,对吗?两者在Chrome中都有效,在Internet Explorer中也不起作用。它使用$'dropdown'.html返回第一个OptionControl上所需的对象。如果有效,我将更新问题..html不是函数,而.html=;运行但不清除列表可能您也没有包括jQuery。
$("#dropdown").empty()
document.getElementById("dropdown").options.length = 0;
$('#dropdown').empty();