How to stylize text in an alert box? [duplicate]

百般思念 提交于 2020-12-12 02:07:33

问题


Possible Duplicate:
How to get Text BOLD in Alert or Confirm box?

In the following example I need to add styles to the word alert, so it says:

Hello! I am an alert box!

Here is my code:

<html><head>
   <script type="text/javascript"> 
      function show_alert() 
      {
         alert("Hello! I am an alert box!"); 
      } 
   </script></head><body>
   <input type="button" onclick="show_alert()" value="Show alert box" />
</body></html>

回答1:


Basically it's impossible. You don't have access to OS level from inside the browser.

All you can do is using a custom modal popup. You can find tons of ready to use modal popup plug ins here or here

window.alert accept an string as it's argument. You can't style an string

From MDN:

message is a string of text you want to display in the alert dialog, or, alternatively, an object that is converted into a string and displayed.




回答2:


The alert box is a browser window and part of the OS, not the DOM, so unfortunately you can't apply styles to it.

The easiest solution is to use one of many existing modal dialogs along with the required Javascript library of the dialog you choose.

The alternative is to mimic an alert box by overlaying a specialized <div class="yourAlertClass"> on your page, using Javascript or a custom library (like moo tools or jQuery) for the animations.




回答3:


You can't.

I think what you are thinking of is a modal popup. Have a look in JQuery UI, but there are plenty of other libraries you can use.




回答4:


Alert, confirm and prompt can not be styled. They vary from browser to browser.

To make a styled "alert box" ( dialog ) you should use an UI library - jQuery UI for example



来源:https://stackoverflow.com/questions/7853321/how-to-stylize-text-in-an-alert-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!