我有一個名爲「selectMe」的數組,它由一個包含字符串的變量組成,例如:12P,5B,10C等,這是超鏈接的「href」值,I需要找到並添加「選擇」的類到這個數組中。爲了打破陣列我有:找到一個具有一定價值的href
function selectPrevious(selections){
// split into array
var selectMe = selections.split(", ")
for (var i = 0; i < selectMe.length; i++){
$('#theater a').search(selectMe[i]).addClass('selected');
}
}
我試着做find()
代替search()
以及許多其他迭代,但仍然沒能實現我想要什麼,我該怎麼辦呢?
編輯
使用這裏提供的答案我已經把它改爲這個之一:
function selectPrevious(selections){
// split into array
if(typeof selections !== "undefined"){
var selectMe = selections.split(", ");
for (var i = 0; i < selectMe.length; i++){
$('#theater a[href*='+selectMe[i]+']').addClass('selected');
}
}
}
我不得不添加了 「如果(!的typeof選擇== 」未定義「)」因爲否則它會在IE上拋出我的錯誤。無論如何,我仍然無法將「selected」類添加到數組中的值,我是否錯過了某些東西?還是我做錯了什麼?
還有什麼在'selections'變量? – 2010-11-14 05:07:28
選擇是一個包含如下值的數組:12P,5B,10C等 – Tsundoku 2010-11-14 05:09:20
以及什麼是12P或5B或10C到任何超鏈接?它是任何一種屬性?或者它是超鏈接的ID? – 2010-11-14 05:11:28