我有這個功能通過函數調用jQuery變量作用域?
function update_prices(product_selector){
//kind of a hack to account for the sometimes having a professional price and sometimes not
var price_count = product_selector.find('small.rt').length;
for (i=0;i<=price_count;i++)
{
if(i == 0){
var standard_selector = product_selector.find('small.rt:eq('+ i +')');
var standard_price = standard_selector.attr('data');
}
if(i == 1){
var business_selector = product_selector.find('small.rt:eq('+ i +')');
var business_price = business_selector.attr('data');
}
if(i == 2){
var professional_selector = product_selector.find('small.rt:eq('+ i +')');
var professional_price = professional_selector.attr('data');
}
}
}
,我有這個塊的代碼調用它
....
....
product_selector.find(".active_selector").removeClass('active_selector');
update_prices(product_selector);
....
....
standard_selector.text("something");
business_selector.text("something else");
professional_selector.text("another thing");
我的問題是如何保持的範圍爲三個變量standard_selector
business_selector
和professional_selector
是獲得創建在update_prices函數中
是否希望能夠訪問update_prices()函數之外的那些變量? – maxedison
您將它們作爲數組或對象返回,然後從函數調用中檢索它們。 – Blazemonger
是直接在函數調用後 – Trace