为什么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