下面提到的脚本正常工作(1)但如果我把elseif条件不能正常工作(2)
我如何使用elseif条件
第1步
function cl_Indexchange(sender, eventArgs) {
var pnl = document.getElementById("pnlSchedule");
var item = eventArgs.get_item();
if (item.get_text() == "Call Back Later (CBL)") {
pnl.style.display = "block";
} else
{
pnl.style.display = "none";
}
}
第2步
function cl_Indexchange(sender, eventArgs) {
var pnl = document.getElementById("pnlSchedule");
var item = eventArgs.get_item();
if (item.get_text() == "Call Back Later (CBL)") {
pnl.style.display = "block";
} else
(item.get_text() == "Call Back After Explanation (CBE)") {
pnl.style.display = "block";
}
elseif
(item.get_text() == "Call Back After Explanation (CBE)") {
pnl.style.display = "block";
}elseif
{
pnl.style.display = "none";
}
}
答案 0 :(得分:0)
因为您在此if-else
的结构不正确。 else
将始终作为if
的最后声明,else if
之间的else
将来if
和{{1}之间需要提供空格如下所示:
if (item.get_text() == "Call Back Later (CBL)") {
pnl.style.display = "block";
}
else if(item.get_text() == "Call Back After Explanation (CBE)") {
pnl.style.display = "block";
}
else
{
pnl.style.display = "none";
}
此外,您可以合并else if
部分,因为它做同样的事情,您可以使用单个if
和else
声明:
if (item.get_text() == "Call Back Later (CBL)" || item.get_text() == "Call Back After Explanation (CBE)") {
pnl.style.display = "block";
}
else
{
pnl.style.display = "none";
}
答案 1 :(得分:0)
您的if-else
结构不合适。试试这个
function cl_Indexchange(sender, eventArgs) {
var pnl = document.getElementById("pnlSchedule");
var item = eventArgs.get_item();
if (item.get_text() == "Call Back Later (CBL)") {
pnl.style.display = "block";
} else if (item.get_text() == "Call Back After Explanation (CBE)") {
pnl.style.display = "block";
} else {
pnl.style.display = "none";
}
}