How to personalize alert buttons - window.confirm() and window.alert() [duplicate]

谁说我不能喝 提交于 2019-11-29 01:51:32

I wont discover anything new here. And the comments created say all the most relevant information.

You should look at open source alternatives that have great support and are easy to customize. Take a look at BootBoxJS (it depends on jQuery).

In that site you can find examples of alerts, dialogs, and other useful tools. e.g.

To use the mentioned soft:

  1. Download the js library compressed (including js, css, etc)
  2. Unzip the file whatever you want to.
  3. Then copy and paste the example code and save this as example.html or whatever you want to.
  4. Now change the links to make it point to your downloaded files (see how I changed my file)
  5. Save the file and test it with your preferred browser.

I just did it and it works perfect! (Under Firefox and Chromium)

NOTE: I tested it with the new version of BootStrap (v.3) and it doesn't work.

The simple answer is that you can't , prompts do not support this feature,

However you could use Jquery or build your own modal/ dialog to emulate this functionality.

See the jQuery UI Dialog for ideas and examples.

Setting up the example from the page check out the jsfiddle

HTML:

<div id="dialog-confirm" title="Empty the recycle bin?">
  <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>

<p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p>

JS

$(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:140,
      modal: true,
      buttons: {
        "Delete all items": function() {
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });

The CSS is to large to post, but you can link this file :

http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css

No. A simple review of the docs may be useful. Java applets have similarly (but distinctly different) styled UI elements that may be what you've seen in the past.

If you wanted to you could create your own dialog boxes using HTML/CSS/JavaScript that act like user agent dialog boxes, but that's a lot of work for the result.

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