我试图使用jquery在特定位置/索引中追加选项值。如何在jQuery中的特定索引中追加选项值
这是我的代码:
function refreshDropDown(target,option){
var arrDatabases = getDatabases();
var numOfDatabases = arrDatabases.length;
var hasPe= jQuery.inArray("pe",arrDatabases) >=0 ;
var onlyPe= (jQuery.inArray("pe",arrDatabases) >=0 && numOfDatabases == 1);
if(!hasPe && !onlyPe && numOfDatabases !=0){
jQuery(".lookForSelector option[value='Publishers']").remove();
**jQuery(target).append(jQuery('<option> </option>').val('Publishers').html('Publisher'));**
}
}
在这上面的代码中,我要与标题“出版商”在第19位追加值“出版商”。现在它正在追加到最后一个索引中。变量目标的值是“.lookForSelector”。
感谢您的及时帮助。
http://stackoverflow.com/questions/6912831/how -to-insert-option-at-specified-index-of-selectmultiple-in-html请搜索一下 – 2013-03-13 13:12:28