2017-08-21 25 views
0

是否可以實現JS警報消息中文本的格式化?在警報消息中格式化並添加圖像

<script> 
function myFunction() { 
alert("1.Enter your name. 2. Enter your mobile no. 3.Do not press back 
button."); 
} 
</script> 

我希望這3條消息一個在另一個下面出現。我試過了:

<p>1.Enter your name.</p><p> 2. Enter your mobile no.</p><p> 3.Do not 
press back button.</p> 

沒有工作。另外,希望最後的消息後添加此IMG SRC標籤:

<img src="http://forums.nextgames.com/resources/emoji/smiley.png" alt="smily"/> 

謝謝。

+0

複製到https://stackoverflow.com/questions/17470817/format-the-text-in-javascript-警示框。您應該考慮使用Bootstrap模式或jQuery UI –

+0

[在javascript警報框中格式化文本的可能的重複](https://stackoverflow.com/questions/17470817/format-the-text-in-javascript-alert-box) – Nisarg

回答

0

瀏覽器警報框不支持呈現HTML,但是你可以像\n換行和\t標籤使用純文本格式。

alert("1.Enter your name.\n2. Enter your mobile no.\n3.Do not press back button."); 
+1

你應該教一個人如何釣魚。這個問題自2013年起有答案。 –

+0

img src標籤呢?如何添加? – Chetan

+0

@Chetan你不能。 – Marty

1

警告框是一個對象,與CSS無關。要做到這一點,你需要創建一個HTML元素並模仿alert()功能。 jQuery UI Modal框爲你做了很多工作。

+0

你可以使用模態這個...只要你想 –

1

嘗試線示例之前加入 「/ N」 「\ N 2」, 「\ N3」