前端之家收集整理的这篇文章主要介绍了
清除选择使用jquery,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以使用JQuery清除html选择对象的
内容?我有一个
函数,它获得一个列表来填充select,并将其附加到select,所以我需要一些
方法清除之前的数据,然后再
添加。
使用
.empty()
$('select').empty().append('whatever');
你也可以使用.html()
,但注意
When .html()
is used to set an element’s content,any content that was in that
element is completely replaced by the new content. Consider the following HTML:
备选:—如果只想选择要删除的选项元素,请使用.remove()
$('select option').remove();
原文链接:https://www.f2er.com/jquery/185083.html