【发布时间】:2018-03-21 12:09:16
【问题描述】:
我正在制作一个简单的过滤系统,其中每个 li 值都有特定的描述。 目前它正在使用 IF 语句,但我想将其转换为开关。这可能吗?
提前致谢。
我的代码:
$("ul.simplefilter").on('click', 'li', function (e) {
if($(this).text() == "Iedereen"){
$("#uitleg p").remove();
$("#uitleg").append("<p>Iedereen</p>");
}
else if($(this).text() == "Coach studentenparticipatie"){
$("#uitleg p").remove();
$("#uitleg").append("<p>Coach studentenparticipatie</p>");
}
else if($(this).text() == "Communicatie"){
$("#uitleg p").remove();
$("#uitleg").append("<p>Communicatie</p>");
}
else if($(this).text() == "Coördinator"){
$("#uitleg p").remove();
$("#uitleg").append("<p>Coördinator</p>");
}
})
【问题讨论】:
-
switch($(this).text)和匹配案例case "Iedereen" :等 -
假设。试试看:
$('#uitleg').html('<p>' + $(this).text() + '</p>');
标签: javascript jquery html if-statement switch-statement