使用javascript更改警报消息文本颜色

使用javascript更改警报消息文本颜色,javascript,Javascript,我正在使用下面的脚本更改脚本的颜色,但显示如下“font color=“red”>Hello world/font>。是否有任何可能的方法更改警报文本的颜色 <html> <head> <title>JavaScript String fontcolor() Method</title> </head> <body> <script type="text/javascript"> var str = new S

我正在使用下面的脚本更改脚本的颜色,但显示如下“font color=“red”>Hello world/font>。是否有任何可能的方法更改警报文本的颜色

<html>
<head>
<title>JavaScript String fontcolor() Method</title>
</head>
<body>
<script type="text/javascript">

var str = new String("Hello world");

alert(str.fontcolor( "red" ));

</script>
</body>
</html>

JavaScript字符串fontcolor()方法
var str=新字符串(“Hello world”);
警报(str.fontcolor(“红色”));
否。
警报()
接受字符串并使用本机小部件呈现它。没有为其设置样式的规定


最接近的方法是通过DOM修改HTML文档以显示消息,而不是使用
alert()

否。alert()接受字符串并使用本机小部件呈现它。没有设置样式的规定。

您可以使用JQuery解决您的问题

<html>
<head>
<meta charset="utf-8" />
<title>JavaScript String fontcolor() Method</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-                  ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
 $( "#dialog-message" ).dialog({
  modal: true,
  buttons: {
  Ok: function() {
   $( this ).dialog( "close" );
   } 
}});
});
</script>
</head>

<body>
 <div id="dialog-message" title="My Dialog Alternative">
 <p style='color:red'> Hello world </p>
 </div>
</body>
 </html>

JavaScript字符串fontcolor()方法
$(函数(){
$(“#对话框消息”).dialog({
莫代尔:是的,
按钮:{
好的:函数(){
$(此).dialog(“关闭”);
} 
}});
});

你好,世界

希望这些帮助:

<!doctype html>
<html>
<head>
<title>JavaScript String fontcolor() Method</title>
<style>
#alertoverlay{display: none;
    opacity: .8;
    position: fixed;
    top: 0px;
    left: 0px;
    background: #FFF;
    width: 100%;}

#alertbox{display: none;
    position: fixed;
    background: #000;
    border:7px dotted #12f200;
    border-radius:10px; 
    font-size:20px;}

#alertbox > div > #alertboxhead{background:#222; padding:10px;color:#FFF;}
#alertbox > div > #alertboxbody{ background:#111; padding:40px;color:red; } 
#alertbox > div > #alertboxfoot{ background: #111; padding:10px; text-align:right; }
</style><!-- remove padding for normal text alert -->

<script>
function CustomAlert(){
    this.on = function(alert){
        var winW = window.innerWidth;
        var winH = window.innerHeight;

        alertoverlay.style.display = "block";
        alertoverlay.style.height = window.innerHeight+"px";
        alertbox.style.left = (window.innerWidth/3.5)+"pt";
        alertbox.style.right = (window.innerWidth/3.5)+"pt"; // remove this if you don't want to have your alertbox to have a standard size but after you remove modify this line : alertbox.style.left=(window.inner.Width/4);
    alertbox.style.top = (window.innerHeight/10)+"pt";
        alertbox.style.display = "block";
        document.getElementById('alertboxhead').innerHTML = "JavaScript String fontcolor() Method :";
        document.getElementById('alertboxbody').innerHTML = alert;
        document.getElementById('alertboxfoot').innerHTML = '<button onclick="Alert.off()">OK</button>';
    }
    this.off = function(){
        document.getElementById('alertbox').style.display = "none";
        document.getElementById('alertoverlay').style.display = "none";
    }
}
var Alert = new CustomAlert();
</script>
</head>
<body bgcolor="black">
<div id="alertoverlay"></div>
<div id="alertbox">
  <div>
    <div id="alertboxhead"></div>
    <div id="alertboxbody"></div>
    <div id="alertboxfoot"></div>
  </div>
</div>
<script>Alert.on("Hello World!");</script>
</body>
</html>

JavaScript字符串fontcolor()方法
#alertoverlay{显示:无;
不透明度:.8;
位置:固定;
顶部:0px;
左:0px;
背景:#FFF;
宽度:100%;}
#alertbox{显示:无;
位置:固定;
背景:#000;
边框:7px点#12f200;
边界半径:10px;
字体大小:20px;}
#alertbox>div>#alertboxhead{背景:#222;填充:10px;颜色:#FFF;}
#alertbox>div>#alertboxbody{背景:111;填充:40px;颜色:红色;}
#alertbox>div>#alertboxfoot{背景:#111;填充:10px;文本对齐:右;}
函数CustomAlert(){
this.on=功能(警报){
var winW=window.innerWidth;
var winH=window.innerHeight;
alertoverlay.style.display=“block”;
alertoverlay.style.height=window.innerHeight+“px”;
alertbox.style.left=(window.innerWidth/3.5)+“pt”;
alertbox.style.right=(window.innerWidth/3.5)+“pt”//如果您不想让alertbox具有标准大小,但在删除后,请删除该行:alertbox.style.left=(window.inner.Width/4);
alertbox.style.top=(window.innerHeight/10)+“pt”;
alertbox.style.display=“block”;
document.getElementById('alertboxhead').innerHTML=“JavaScript字符串fontcolor()方法:”;
document.getElementById('alertboxbody')。innerHTML=alert;
document.getElementById('alertboxfoot')。innerHTML='OK';
}
this.off=函数(){
document.getElementById('alertbox').style.display=“无”;
document.getElementById('alertoverlay').style.display=“无”;
}
}
var Alert=新的CustomAlert();
警惕。打开(“你好,世界!”);

其概念如下:

不,这是不可能的,但您可以使用自定义警报框,由来自Jquery UI的divtry模式消息组成,停止使用付费URL缩短器-这些被视为垃圾邮件。