问题
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