向上/向下移动项目选择

时间:2010-03-10 18:49:31

标签: javascript jquery html

我想知道是否可以在不必完全重建的情况下更改选择控件中的事物顺序?

是否有javascript函数,我可以在select?

中更改特定选项的“索引”

由于

2 个答案:

答案 0 :(得分:5)

当然,只需在jQuery中找到两个元素(通过他们的ID或其他),所以你有两个对象,然后在它们上面使用before()

var o1=$("#opt1");
var o2=$("#opt2");
o2.insertBefore(o1);

答案 1 :(得分:1)

尝试使用Array.splice

// Remove the option from the list:
var option = selectElement.options.splice(indexOfOptionToRemove,1);

// and put it back in at the new index:
selectElement.options.splice(indexOfNewOptionPosition,option);
相关问题