如何个性化警报按钮 - window.confirm()和window.alert() [英] How to personalize alert buttons - window.confirm() and window.alert()

查看:242
本文介绍了如何个性化警报按钮 - window.confirm()和window.alert()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过许多网站都使用不同的按钮文字对其提醒和确认框进行了个性化。



默认情况下,这就是JavaScript window.confirm()函数将输出:

  + --------- -------------------- + 
|来自网页的留言|
+ ----------------------------- +
|弹出文本|
| |
| |
| |
| |
| [确定] [取消] |
+ ----------------------------- +

但是,如果我想要自定义标题文本和自定义按钮文本等自定义怎么办?

  + ----------------------------- + 
|我的自定义标题|
+ ----------------------------- +
|弹出文本|
| |
| |
| |
| |
| [你好] [GOODBYE] |
+ ----------------------------- +

这可以用JavaScript,Jquery或AJAX(或其他语言)实现吗?如果是的话,你能告诉我一个例子吗?谢谢!

解决方案

我在这里找不到任何新东西。创建的评论说明了所有最相关的信息。



您应该查看具有强大支持且易于自定义的开源替代方案。看看(包括js,css等)

  • 解压缩文件,无论你想要什么。

  • 然后复制并粘贴示例代码并将其另存为 example.html 或者您想要的任何内容。

  • 现在更改链接以使其指向您下载的文件(请参阅我如何更改我的文件

  • 保存文件并使用首选浏览器进行测试。

  • 我刚刚做到了,它完美无缺! (在Firefox和Chromium下)



    注意:我使用新版本的BootStrap(v.3)对其进行了测试,但它不起作用。


    I have seen many websites that have personalized their alert and confirmation boxes with different button text.

    By default, this is what the JavaScript window.confirm() function would output:

    +-----------------------------+
    |Message from webpage         |
    +-----------------------------+
    |Popup text                   |
    |                             |
    |                             |
    |                             |
    |                             |
    |   [Ok]     [Cancel]         |
    +-----------------------------+
    

    But, what if I wanted some customization like custom header text, and custom button text?

    +-----------------------------+
    |My custom Header             |
    +-----------------------------+
    |Popup text                   |
    |                             |
    |                             |
    |                             |
    |                             |
    |   [HELLO]     [GOODBYE]     |
    +-----------------------------+
    

    Can this be achieved in JavaScript, Jquery, or AJAX (or another language)? If so, could you please show me an example? Thanks!

    解决方案

    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.

    这篇关于如何个性化警报按钮 - window.confirm()和window.alert()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆