【发布时间】:2018-05-04 12:30:25
【问题描述】:
我正在尝试为同一输出“数学书”添加多个值。我想我缺少一些关于如何格式化括号中的值的基本知识。
<script type="text/javascript">
<!--
var book = "maths";
if (book == "history") {
document.write("<b>History Book</b>");
/*How to add more options below besides "maths" so the output will be "Maths
Book". I want the output to be "Maths Book" also when user enters
mathemathics, mata, maths book...
Do I need more else if lines or I can put additional values in in brackets*/
} else if (book == "maths") {
document.write("<b>Maths Book</b>");
} else {
document.write("<b>Unknown Book</b>");
}
//-->
</script>
<p>Set the variable to different value and then try...</p>
【问题讨论】:
-
您正在寻找logical OR operator,但如果您当前的资源足以推荐
<!-- … //-->,您还应该找到学习JavaScript 的更新资源。 -
你的意思是
if (book.toLowerCase().indexOf("math") !=-1) -
我正在使用 tutorialspoint.com PDF JS 教程。
<!-- … //-->有什么问题
标签: javascript