添加选项使用jQuery列表 [英] adding option to list using jquery
本文介绍了添加选项使用jQuery列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var list =["haider","faisal","adnan","kami","asad"]
var handles = list.sort();
var options = '';
for (var i = 0; i < handles.length; i ++) {
options += '<option value="' + handles[i] + '">' + handles[i] + '</option>';
}
$('#listBox').html(options);
现在我要插入"faizan",并且保持列表顺序不变,该怎么做?
now i want to insert "faizan" and the list order is maintained any idea how to do it?
推荐答案
(' #listBox').html(options);
('#listBox').html(options);
现在我要插入"faizan",并且保持列表顺序不变,该怎么做?
now i want to insert "faizan" and the list order is maintained any idea how to do it?
El-salmo 3likom wa ra7mat ALLAH我们巴拉卡托,
亲爱的,
另一个解决方案:
您可以在列表中添加"faizan"
El-salmo 3likom wa ra7mat ALLAH we Barakatoh,
Dear,
another Solution:
you can add "faizan" to the list
var list =["haider","faisal","adnan","kami","asad"]
function addOption(Obj)
{
//clear list
(#listBox').html( ); // 添加新选项 list.push(Obj); // 对数组进行排序 var handles = list.sort(); var 选项= ' '; for ( var i = 0 ; i < handles.length;我++){ 选项+ = ' < option value =' +句柄[i] + ">' + handles [i] + ' </option>'; }
('#listBox').html(""); //add new option list.push(Obj); //sort the array var handles = list.sort(); var options = ''; for (var i = 0; i < handles.length; i ++) { options += '<option value="' + handles[i] + '">' + handles[i] + '</option>'; }
这篇关于添加选项使用jQuery列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文