我正在尝试摆脱经典 ASP。我开发了替代技术来处理 HTML/JavaScript 中的几乎所有内容。但是,我仍然需要某种方法来替换以下内容:
<% if this then %>
<div>Wow. This. Totally this. Isn't this great?</div>
<% else %>
<div>You're really missing out on this.</div>
<% end if %>
有没有办法在纯 HTML/JavaScript 中完成条件分支/条件代码?
最佳答案
客户端脚本的 document.writeln:
<html>
<head>
</head>
<body>
<br />Some html code before<br /><br />
<script language="javascript">
var This = true;
if(This){
document.writeln("<div>Wow. This. Totally this. Isn't this great?</div>");
}
else{
document.writeln("<div>You're really missing out on this.</div>");
}
</script>
<br />Some html code after<br /><br />
<script language="javascript">
var This = false;
if(This){
document.writeln("<div>Wow. This. Totally this. Isn't this great?</div>");
}
else{
document.writeln("<div>You're really missing out on this.</div>");
}
</script>
<br />Some other html code after<br /><br />
</body>
注意:在你的例子中你使用了“this”,我使用了“This”,JavaScript中的“this”是一个保留字
关于javascript - 经典 ASP 流控制的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36013474/