开发者

add item to a listbox using jquery

How to add item to a listBox using jquery.

for example in the following listbox

<option value="1"></option>
<option value="2">item 2</option>
<option value="3">item 3</option>
<option value="4">item 4</opti开发者_运维百科on>
<option value="0">All</option>


$('#Select1').append('<option value="5">item 5</option>'); // adds item 5 at the end
$('#Select1 option').eq(0).after('<option value="new">new</option>'); // add new at the second position.


Several methods are there. You can use

$('<option value="5">item 5</option>').appendTo('#listbox');

$('#listbox').append('<option value="5">item 5</option>');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜