因此,我必须在此有序列表中添加第5个项目,并且第5个项目必须超链接。我正将我在网上阅读的内容完全放上,但它不起作用。
// create an ordered list
document.write("<ol>");
document.write("<li>Reduce spending on non-necessities.</li>")
document.write("<li>Use extra money to pay off debt,starting with the
highest-interest credit card.</li>")
document.write("<li>Continue paying off debts until you are debt free.</li>")
document.write ("<li>Put a fixed percent of your pay aside in savings.</li>")
document.write ("<li> <a href="https://www.financial-planning.com/"> Financial Planning </a> </li>")
document.write("</ol>");
我得到这个错误。 “解析错误:预期的令牌https
最佳答案
尝试用单引号将li
换行:
document.write ('<li> <a href="https://www.financial-planning.com/"> Financial Planning </a> </li>')
或:使用ES6
Template literals
document.write (`<li> <a href="https://www.financial-planning.com/"> Financial Planning </a> </li>`)
或:您可以通过在前缀
\
之前转义内部双引号:document.write ("<li> <a href=\"https://www.financial-planning.com/\"> Financial Planning </a> </li>")
关于javascript - HTML中的超链接(有序列表),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52082695/