對象值我有一個卡一個數組對象:for循環不能找到在陣列
$(document).ready(function() {
var totalPlayer = 12;
var cards = [
{"card": 2, "value": 2, "suit": "d"},
{"card": 2, "value": 2, "suit": "c"},
{"card": 2, "value": 2, "suit": "h"},
{"card": 2, "value": 2, "suit": "s"},
{"card": 3, "value": 3,...
{"card": "a", "value": 11, "suit": "s"}];
$('#butStart').click(processIt);
和循環:
function processIt() {
for (var i = 0; i < cards.length; i++) {
if (cards[i].card === "a" && totalPlayer > 11) {
cards[i].value = 1;
}
else if (cards[i].card === "a") {
cards[i].value = 11;
}
}
alert(cards[50].value + cards[50].card);
}
我無法弄清楚,爲什麼我收到錯誤消息「不能讀取未定義的屬性'卡'
你有沒有嘗試過使用'for(var i = 0; i
summea
2012-02-18 02:18:54
你剛纔在你的卡片數組中遇到了一個錯字 – Dampsquid 2012-02-18 02:21:04
是的,發現它是雙',',對不起,謝謝你們。 – user1114060 2012-02-18 02:23:05