javascript警报不适用于某些特定文本

时间:2012-01-29 05:28:00

标签: javascript

<a href="term_1.html" onClick="alert('A caldera is a circular shaped
landform depression caused by the eruption of a large, near surface
body of magma.'); return false">caldera</a>

我尝试运行此块但它无效。当我在alert中写一些其他消息时(除此之外)它可以正常工作。有人会告诉我确切的问题吗?

3 个答案:

答案 0 :(得分:5)

您的字符串换行到新行,导致onclick处理程序中断。试试这个:

<a href="term_1.html" onclick="alert('A caldera is a circular shaped landform depression caused by the eruption of a large, near surface body of magma.'); return false">caldera</a>

演示:http://jsfiddle.net/Q9gbV/1/

答案 1 :(得分:3)

看来你有一个跨越多行的javascript字符串。将警报的整个文本保存在一行(它将在屏幕上运行),它应该可以正常工作。

或者,您可以在字符串的每一行末尾添加\,例如:

<a href="term_1.html" onClick="alert('A caldera is a circular shaped\
landform depression caused by the eruption of a large, near surface\
body of magma.'); return false">caldera</a>

答案 2 :(得分:1)

删除文字中的新行。只需将文本放在一行就可以了。