我試圖使用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