小编Deb*_*rah的帖子

你会如何简化这段 javascript 代码?

在这里寻找一些建议来改进我的编码。

你如何使这段代码更短/更有效?

var resultsConstructionYear = readCookie('constructionYear');
if (resultsConstructionYear == 3) {
    document.getElementById('resultsUserConstructionYear').innerHTML = "Avant 1944";
} else if (resultsConstructionYear == 4) {
    document.getElementById('resultsUserConstructionYear').innerHTML = "Entre 1945 et 1974";
} else if (resultsConstructionYear == 5) {
    document.getElementById('resultsUserConstructionYear').innerHTML = "Entre 1975 et 1989";
} else if (resultsConstructionYear == 6) {
    document.getElementById('resultsUserConstructionYear').innerHTML = "Entre 1990 et 2009";
} else if (resultsConstructionYear == 7) {
    document.getElementById('resultsUserConstructionYear').innerHTML = "Après 2010";
} else {
    document.getElementById('resultsUserConstructionYear').innerHTML = "Inconnue";
}
Run Code Online (Sandbox Code Playgroud)

javascript arrays optimization performance jquery

-1
推荐指数
1
解决办法
42
查看次数

标签 统计

arrays ×1

javascript ×1

jquery ×1

optimization ×1

performance ×1