简体   繁体   English

HTML中的超链接(有序列表)

[英]Hyperlink In HTML in an ordered list

So I have to add a 5th item to this ordered list and the 5th item has to be hyperlinked. 因此,我必须在此有序列表中添加第5个项目,并且第5个项目必须超链接。 I am putting exactly what I am reading online and it is not working. 我正在将我在网上阅读的内容完全放上,但它不起作用。

// 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>");

I get this error. 我得到这个错误。 "Parsing error: enexpected token https “解析错误:预期的令牌https

Try wrapping li with single quotes: 尝试用单引号将li包裹起来:

 document.write ('<li> <a href="https://www.financial-planning.com/"> Financial Planning </a> </li>') 

OR: With ES6 Template literals 或:使用ES6 Template literals

 document.write (`<li> <a href="https://www.financial-planning.com/"> Financial Planning </a> </li>`) 

OR: You can escape the inner double quotes by prefixing \\ : 或者:您可以通过在前缀\\前面转义内部双引号:

 document.write ("<li> <a href=\\"https://www.financial-planning.com/\\"> Financial Planning </a> </li>") 

You have to pass " char as it is to write function. To do it you can use escape char () or single quote (') 您必须像传递函数一样传递“ char。为此,您可以使用转义char()或单引号(')

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>");

When you have a string and you want to put quotes inside it, use double-quotes first and inside single-quotes: 当您有一个字符串并且想要在其中加上引号时,请首先在双引号和单引号内使用:

"<li> <a href='https://www.financial-planning.com/'> Financial Planning </a> </li>"

'<li> <a href="https://www.financial-planning.com/"> Financial Planning </a> </li>'

Just use single quotes on the outside. 只需在外面使用单引号即可。

Like so: 像这样:

'<li> <a href="https://www.financial-planning.com/"> Financial Planning </a> </li>'

It's not formatted correctly. 格式不正确。 Remove the double quotes and add single around the address. 删除双引号,并在地址周围添加单引号。

try the following: 尝试以下方法:

"<li> <a href='https://www.financial-planning.com/'> Financial Planning </a> </li>"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM