2012-01-29 26 views
0
<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(除此之外)中寫入其他消息時,它可以正常工作。有人會告訴我確切的問題是?JavaScript警告不適用於某些特定文本

回答

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/

+0

我會和Blender一起回答。單一線比我在我的演示中表現出來的'\'更好,而這個'\'大部分在FYI。 – ryanlahue 2012-01-29 05:34:48

+1

@rrr:我從來不知道使用HTML工作的人。你有我的+1。 – Blender 2012-01-29 05:36:34

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> 
+0

感謝您提供給我這個提示 – Inactive 2012-01-29 05:37:50

1

刪除您的文本換行。只需將文本放在一行即可使用。

相關問題