未捕获的类型错误:无法读取未定义的属性“basePrice”
Uncaught TypeError: Cannot read property 'basePrice' of undefined
我不确定错误(未捕获的类型错误:无法读取未定义的属性'basePrice'(是什么意思,因为该值在第一部分中有明确定义。
当我展开错误消息时,它会标记更新的价格,然后是两个匿名函数。我不确定我是否应该寻找错别字或我是否使用了不正确的逻辑。
<script>
(function() {
var plans = {
basic: {
pricingChart: false,
pricingChart2: false,
basePrice: 0
},
standard: {
pricingChart: false,
pricingChart2: false,
basePrice: 2.99
},
premium: {
pricingChart: true,
pricingChart2: false,
basePrice: 49.99
},
enterprise: {
pricingChart: true,
pricingChart2: true,
basePrice: 500
}
};
var viewerLevels = {
500: 10.99,
2500: 10.99,
5000: 29.99,
10000: 39.99
};
var userLevels = {
1: 10.99,
2: 20.99,
3: 30.99,
4: 40.99
};
var selectedPlan = "free";
var viewerLevel = null;
var userLevel = null;
$( ".plan .select-button" ).on( "click", function( event ) {
selectedPlan = $( this ).closest( ".plan" ).attr( "data-plan" );
var planInfo = plans[ selectedPlan ];
if ( planInfo.pricingChart ) {
$( "#pricingChart" ).removeClass( "not" );
} else {
$( "#pricingChart" ).addClass( "not" );
viewerLevel = null;
}
if ( planInfo.pricingChart2 ) {
$( "#pricingChart2" ).removeClass( "not" );
} else {
$( "#pricingChart2" ).addClass( "not" );
userLevel = null;
}
var showPricingChart = "#topPricingChart";
if ( planInfo.pricingChart ) {
showPricingChart = "#pricingChart";
}
$( "html,body" ).animate({
scrollTop: $( showPricingChart ).offset().top
}, "slow" );
updatePrice();
});
$( ".pricingLevel" ).on( "click", function() {
viewerLevel = $( this ).attr( "data-viewer" );
updatePrice();
});
$( ".pricingLevel2" ).on( "click", function() {
userLevel = $( this ).attr( "data-user" );
updatePrice();
});
function updatePrice() {
var basePrice = plans[ selectedPlan ].basePrice;
var viewerPrice = 0;
if ( viewerLevel ) {
viewerPrice = viewerLevels[ viewerLevel ];
}
var userPrice = 0;
if ( userLevel ) {
userPrice = userLevels[ userLevel ];
}
var totalPrice = basePrice + viewerPrice + userPrice;
$( ".pricingLargeAmount" ).text( totalPrice );
}
updatePrice();
})();
</script>
该错误表示未定义plans[ selectedPlan ]
。
selectedPlan == "free"
和plans.free
不存在。
该错误意味着 selectedPlan
的值不是 plans
的属性名称。例如,您正在将其初始化为 "free"
但plans
没有这样的属性。 plans["free"]
undefined
,因此您"无法读取未定义的属性'basePrice'">
相关文章:
- TypeError:无法读取属性'推'未定义的JavaScript
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 未捕获的类型错误:无法读取属性'删除'的未定义
- AngularJS指令出错-无法读取属性'编译'的未定义
- 看到“;未捕获的类型错误:无法读取属性'weight'未定义的“;尽管按照字面上的指示
- angularjs无法读取未定义的属性then
- 无法读取属性'材料'未定义的Three.js
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- JavaScript承诺-无法读取属性'那么'的未定义
- 未捕获的类型错误:无法读取属性'中止'的未定义
- 角度推入数组给出:TypeError:无法读取属性'推'的未定义
- Javascript未捕获类型错误:无法读取属性'0'的未定义
- jQuery控制台错误:无法读取属性'top'的未定义
- TypeError:无法读取属性'findAll'的未定义
- 无法读取属性'errcap'未定义的jqgrid
- 无法读取未定义的属性“rid”
- 未捕获的类型错误: 无法读取未定义的属性“图像”
- 可以't读取'getHTML'未定义的Liferay CK Editor内容
- 在node.js中未定义读取属性错误