Javascript 当我想更改默认确认框的框标题和按钮标题时。我选择了jQueryUI对话框插件

Javascript 当我想更改默认确认框的框标题和按钮标题时。我选择了jQueryUI对话框插件,javascript,alert,Javascript,Alert,当我有以下情况时: function testConfirm() { if (confirm("Are you sure you want to delete?")) { //some stuff } } 我已将其更改为: function testConfirm() { var $dialog = $('<div></div>') .html("Are you sure you want to delete?") .dialog(

当我有以下情况时:

function testConfirm() {
  if (confirm("Are you sure you want to delete?")) {
    //some stuff
  }
}
我已将其更改为:

function testConfirm() {

  var $dialog = $('<div></div>')
    .html("Are you sure you want to delete?")
    .dialog({
      resizable: false,
      title: "Confirm Deletion",
      modal: true,
      buttons: {
        Cancel: function() {
          $(this).dialog("close");
        },
        "Delete": function() {
          //some stuff
          $(this).dialog("close");
        }
      }
    });

  $dialog.dialog('open');
}
函数testConfirm(){
变量$dialog=$('')
.html(“确实要删除吗?”)
.对话({
可调整大小:false,
标题:“确认删除”,
莫代尔:是的,
按钮:{
取消:函数(){
$(此).dialog(“关闭”);
},
“删除”:函数(){
//一些东西
$(此).dialog(“关闭”);
}
}
});
$dialog.dialog('open');
}
你可以看到他在这里工作



希望能有所帮助。

谢谢,但我对使用自定义提醒框不感兴趣顺便说一句,您不能更改标题的原因,是为了防止恶意网站诱使用户认为警报来自其操作系统或其他内容。注意:另一个用户试图编辑此答案,以表明提供的链接指向检测到恶意软件的网站。无意冒犯,但这些警报看起来非常丑陋。SweetAlert比这个漂亮多了。它适用于IE,但不适用于Firefox。“谢谢你,还是一样,又快又脏,但可能会很有用。”达斯。我真该提一下。它使用VBScript。你必须用谷歌搜索如何让VBScript在firefox中运行。@Dath-PS我不知道是否有可能在firefox上运行VBScript的方法。我将创建另一个主题,名为“如何在firefox中运行此vb脚本”,并发布我在上面给您的代码,看看是否有人能想出任何办法。@Darth-尽管我会使用Rahul的解决方案。只需使用一些JQuery,这真的很简单!两张反对票,一张赞成票。。。但是没有评论说我为什么被否决。。。我认为这是一个有效的解决方案。。。至少在IE中:/@Chris Fulstow我喜欢vbscript,我希望vbscript能与javascript一起标准化。这样我就可以在不混淆区分大小写的情况下编写脚本,所有流行的浏览者都会遵守我的命令。哈哈哈哇,评论的票数比答案多。。。对于第二部分的回答虽然这是一个答案,而且事实上是正确的,但我已经确定,您可以制作自己版本的alert,它将满足您的需要。一个简单的模式并覆盖警报函数调用。这是一个安全/反钓鱼功能吗?我很好奇,不是在争论。@Tim推测,如果你的提醒没有告诉用户他们来自哪个URL,那么模拟另一个网站会更容易;不允许这种定制会迫使JavaScript告诉用户这不是一条合法的消息。@只是出于好奇,现在CSS不能模拟警报行为吗?如果是这样,允许您更改模式警报标题是否仍然存在很大威胁?@Josh您可以通过大量的努力接近,但是本机浏览器警报具有无法模拟的行为,例如冻结浏览器的其余部分、浮动在浏览器UI的顶部,以及作为可以从浏览器屏幕上拖出的单独窗口。创建令人信服的副本非常困难,特别是因为每个浏览器的警报看起来都不同。什么是
someElementId
?我指的是哪个标签?
someElementId
是您设置HTML元素的id。@Manikandenseturaju它在FF和GC上不起作用,因为它们不支持VBScript。您能提出异议吗?我想问题是JavaScript兼容所有平台和浏览器,而不是VBScript,后者是严格意义上的IE和Windows因此,它的使用仅限于Windows。您知道,用户可以很容易地禁用警报吗?你不应该依赖那些!是 啊如果您愿意,Sweelert比您的示例更简单。我刚发了一封信
<script language="VBScript">
Sub myAlert(title, content)
MsgBox content, 0, title 
End Sub 
</script>
Response.Write("<script language=JavaScript> myAlert('Message Header Here','Hi select a valid date'); </script>");
<script>

function alert_confirm(){

      customMsgBox("This is my title","how are you?",64,0,0,0);
}

</script>


<script language="VBScript">

Function customMsgBox(tit,mess,icon,buts,defs,mode)
   butVal = icon + buts + defs + mode
   customMsgBox= MsgBox(mess,butVal,tit)
End Function

</script>

<html>

<body>
<a href="javascript:alert_confirm()">Alert</a>
</body>

</html>
window.alert = function(title, message){
    var myElementToShow = document.getElementById("someElementId");
    myElementToShow.innerHTML = title + "</br>" + message; 
}
<html>
 <head>
   <title>jsConfirmSyle</title>
   <meta http-equiv="Content-Style-Type" content="text/css" />
   <meta http-equiv="Content-Script-Type" content="text/javascript" />
    <script type="text/javascript" src="jsConfirmStyle.js"></script>
    <script type="text/javascript">

      function confirmation() {
       var answer = confirm("Wanna visit google?")
       if (answer){
       window.location = "http://www.google.com/";
       }
     }    

    </script>
    <style type="text/css">
     body {
      background-color: white;
      font-family: sans-serif;
      }
    #jsconfirm {
      border-color: #c0c0c0;
      border-width: 2px 4px 4px 2px;
      left: 0;
     margin: 0;
     padding: 0;
     position: absolute;
    top: -1000px;
    z-index: 100;
   }

  #jsconfirm table {
   background-color: #fff;
   border: 2px groove #c0c0c0;
   height: 150px;
   width: 300px;
  }

   #jsconfirmtitle {
  background-color: #B0B0B0;
  font-weight: bold;
  height: 20px;
  text-align: center;
}

 #jsconfirmbuttons {
height: 50px;
text-align: center;
 }

#jsconfirmbuttons input {
background-color: #E9E9CF;
color: #000000;
font-weight: bold;
width: 125px;
height: 33px;
padding-left: 20px;
}

#jsconfirmleft{
background-image: url(left.png);
}

#jsconfirmright{
background-image: url(right.png);
 }
 < /style>
  </head>
 <body>
<p><br />
<a href="#"
onclick="javascript:showConfirm('Please confirm','Are you really really sure to visit    google?','Yes','http://www.google.com','No','#')">JsConfirmStyled</a></p>
<p><a href="#" onclick="confirmation()">standard</a></p>

</body>
</html>
ie5=(document.getElementById&&document.all&&document.styleSheets)?1:0;
nn6=(document.getElementById&&!document.all)?1:0;

 xConfirmStart=800;
 yConfirmStart=100;

  if(ie5||nn6) {
  if(ie5) cs=2,th=30;
  else cs=0,th=20;
   document.write(
    "<div id='jsconfirm'>"+
        "<table>"+
            "<tr><td id='jsconfirmtitle'></td></tr>"+
            "<tr><td id='jsconfirmcontent'></td></tr>"+
            "<tr><td id='jsconfirmbuttons'>"+
                "<input id='jsconfirmleft' type='button' value='' onclick='leftJsConfirm()' onfocus='if(this.blur)this.blur()'>"+
                "&nbsp;&nbsp;"+
                "<input id='jsconfirmright' type='button' value='' onclick='rightJsConfirm()' onfocus='if(this.blur)this.blur()'>"+
            "</td></tr>"+
        "</table>"+
    "</div>"
  );
   }

 document.write("<div id='jsconfirmfade'></div>");


 function leftJsConfirm() {
  document.getElementById('jsconfirm').style.top=-1000;
  document.location.href=leftJsConfirmUri;
 }
function rightJsConfirm() {
document.getElementById('jsconfirm').style.top=-1000;
document.location.href=rightJsConfirmUri;
 }
function confirmAlternative() {
if(confirm("Scipt requieres a better browser!"))       document.location.href="http://www.mozilla.org";
}

leftJsConfirmUri = '';
rightJsConfirmUri = '';

  /**
   * Show the message/confirm box
  */
    function       showConfirm(confirmtitle,confirmcontent,confirmlefttext,confirmlefturi,confirmrighttext,con      firmrighturi)  {
document.getElementById("jsconfirmtitle").innerHTML=confirmtitle;
document.getElementById("jsconfirmcontent").innerHTML=confirmcontent;
document.getElementById("jsconfirmleft").value=confirmlefttext;
document.getElementById("jsconfirmright").value=confirmrighttext;
leftJsConfirmUri=confirmlefturi;
rightJsConfirmUri=confirmrighturi;
xConfirm=xConfirmStart, yConfirm=yConfirmStart;
if(ie5) {
    document.getElementById("jsconfirm").style.left='25%';
    document.getElementById("jsconfirm").style.top='35%';
}
else if(nn6) {
    document.getElementById("jsconfirm").style.top='25%';
    document.getElementById("jsconfirm").style.left='35%';
}
else confirmAlternative();
        <script type="text/javascript" >
            alert("USER NOTICE "  +"\n"
            +"\n"
            +"New users are not allowed to work " +"\n"
            +"with that feature.");
        </script>
swal({
  title: "Are you sure?",
  text: "You will not be able to recover this imaginary file!",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Yes, delete it!",
  closeOnConfirm: false
},
function(){
  swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
function testConfirm() {
  if (confirm("Are you sure you want to delete?")) {
    //some stuff
  }
}
function testConfirm() {

  var $dialog = $('<div></div>')
    .html("Are you sure you want to delete?")
    .dialog({
      resizable: false,
      title: "Confirm Deletion",
      modal: true,
      buttons: {
        Cancel: function() {
          $(this).dialog("close");
        },
        "Delete": function() {
          //some stuff
          $(this).dialog("close");
        }
      }
    });

  $dialog.dialog('open');
}