我的IDE,RubyMine的,说这是“可能不正确的”。这个javascript为什么不正确?
function update_top_up_prices_via_localStorage(){
var index = localStorage.getItem("volxs");
$('.product-inner').each(function(){
var product = this.getAttribute('data-product-miles');
var cpm = ((localStorage.getItem("cpm_by_volxs_"+product)).split(","))[index];
$(this).find('table tbody tr td').each(function(){
var top_up_miles = Number(this.getAttribute('data-topup-miles'));
var price = Number(top_up_miles * cpm * 1.06);
price = price.toFixed(2);
$(this).text('\u00A3'+price);
})
});
}
我的IDE上var top_up_miles
线,“潜在的无效使用this
这种检查的JavaScript this
说是相同的封闭物,在外部环境。
JS的工作在Chrome和IE9的罚款。它不会在IE8工作。
这是错的?有没有更好的方式来写这个?
我不知道RubyMine(实际上不知道这是什么),但你的代码看起来或多或少。奇怪的纯JavaScript和jQuery混合。尝试使用'$(this).attr('data-topup-miles')'。 “你不能在IE8中工作”是什么意思?任何错误?不正确的值(IE8似乎以不同于其他浏览器的方式处理'toFixed')?另外IE8有控制台('F12'我相信) - 检查那里的错误(你真的需要在加载页面之前触发控制台,我认为)。 – freakish 2012-07-12 11:50:26