gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'basePrice' of undefined

转载 作者:行者123 更新时间:2023-12-02 16:27:23 25 4
gpt4 key购买 nike

我不确定错误(Uncaught TypeError:无法读取未定义的属性“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 不存在。

关于javascript - 未捕获的类型错误 : Cannot read property 'basePrice' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28575039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com