开发者

remove options in my select element

开发者 https://www.devze.com 2023-03-03 12:54 出处:网络
i have the following select element: <select id=\'payTypes\'> <option value=\'1\'>Cash</option>

i have the following select element:

<select id='payTypes'>
  <option value='1'>Cash</option>
  <option value='2'>Check</option>
  <option value='3'>Standard</option>
</select开发者_运维问答>

can someone show me how to remove the option Standard from the list


Use jQuery to get the payTypes select and the eq selector to get the third (it's zero based so i use 2) and then use the remove method: $("#payTypes option").eq(2).remove()

EDIT:

$("#payTypes option").each(function() {
if($(this).val() > 2) { //if it's not check or cash
$(this).remove();
}
}
0

精彩评论

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