爲什麼getColorOptionSelect()返回未定義的值(我確定它有一個調試器的值)。jquery .each() - 返回值undefined
這是肯定的有關範圍的問題,對不起我的無知JS
jQuery(document).ready(function() {
colorSelectID = getColorOptionSelect();
alert(colorSelectID);
function getColorOptionSelect() {
// get label
var selId;
jQuery(".product-options dl label").each(function() {
el = jQuery(this);
// lower case, remove *
var labelText = el.text().toLowerCase().replace("*", "");
if (labelText == 'color') {
//return element
selId = el.parent().next().find("select").attr('id');
return selId;
}
});
// return null;
}
});
謝謝你,這是工作的罰款 – WonderLand