开发者

jQuery: Function to remove all elements of multiple <select>?

I wanna make a function that erases everything inside of a multiple select using jQuery. Also if it could remove some text from text fi开发者_JAVA百科elds it'd be good too.


Try the following to clear all multiple select elements:

$('select[multiple]').empty();

Replace select with a specific element if you do not want to clear all of them. The same applies to the following chunk of code. It can be used to clear all text fields:

$(':text').val('');


Use .empty() to remove child elements from another element.
Example: $("#selectid1,#selectid2").empty()

Without your HTML, it's hard to go into any more detail.


In case you just want to deselect everything and not remove from the DOM, try


$("select").val([]);

or something with a more specific selector.


Try This Removing Options for Multiple Select Drop Down.

$('#FeatureId').multiselect("deselectAll", false).multiselect("refresh");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜