gpt4 book ai didi

javascript - 对 Javascript 很陌生。如何使此代码可扩展/更清洁?

转载 作者:行者123 更新时间:2023-11-30 10:31:26 25 4
gpt4 key购买 nike

<分区>

对于我正在开发的 Web 应用程序,我需要使用根据下拉选择菜单而变化的数据填充表列。我在下面有一个解决方案,它工作正常,但是因为我今天早上才真正开始学习 javascript/JQuery,所以我确信它不是一个很好的解决方案。当我开始使用更大的表格或使用大量下拉字段时,它会变得困惑。我有什么办法可以做得更好吗?

谢谢,

标记

var GBP = new Array();
GBP[0] = "£1";
GBP[1] = "£2";
GBP[2] = "£3";
GBP[3] = "£4";
GBP[4] = "£5";
GBP[5] = "£6";
GBP[6] = "£7";

var EUR = new Array();
EUR[0] = "€1";
EUR[1] = "€2";
EUR[2] = "€3";
EUR[3] = "€4";
EUR[4] = "€5";
EUR[5] = "€6";
EUR[6] = "€7";

var USD = new Array();
USD[0] = "$1";
USD[1] = "$2";
USD[2] = "$3";
USD[3] = "$4";
USD[4] = "$5";
USD[5] = "$6";
USD[6] = "$7";

$(document).ready(function() {

//populate currency column with default values (GBP)
$('#prices tr').each(function(i) {
$(this).find('.currency').html(GBP[i]);
});

//populate the currency column with a value dependent
//on the selector dropdown
$('.currency-select').change(function() {
if($(this).val() == "GBP"){
$('#prices tr').each(function(i) {
$(this).find('.currency').html(GBP[i]);
});
}

if($(this).val() == "EUR"){
$('#prices tr').each(function(i) {
$(this).find('.currency').html(EUR[i]);
});
}

if($(this).val() == "USD"){
$('#prices tr').each(function(i) {
$(this).find('.currency').html(USD[i]);
});
}
});
});

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