Change format and text displayed with JavaScript prompt()?

后端 未结 5 1641
天涯浪人
天涯浪人 2021-01-25 12:53

I\'m using JavaScript\'s prompt() function.

  var favorite = prompt(\'What is your favorite color?\', \'RED\');

I\'m using IE 7

相关标签:
5条回答
  • 2021-01-25 13:03

    No, there isn't.

    The closest you can come is to mock up a fake one using DOM elements.

    0 讨论(0)
  • 2021-01-25 13:04

    Not exactly what's being asked, but the only way I found to give the prompt box some formatting...

    Using this answer, this answer and these HTML symbols, one can get creative and achieve this:


    prompt example

    Demonstration:

    var balls = '\u25CD'.repeat(24),
        blue = '\u27BF', 
        red = '\u274C', 
        yellow = '\u2728', 
        green = '\u2705',
        arrow = '\u25B8';
        
    window.prompt(balls+' \u25C9 '+balls+'\rWhat is your favorite color?\r\t'+arrow+' B\u0332lue '+blue+'\r\t'+arrow+' R\u0332ed '+red+'\r\t'+arrow+' Y\u0332ellow '+yellow+'\r\t'+arrow+' G\u0332reen '+green);

    0 讨论(0)
  • 2021-01-25 13:12

    Yes. By not relying on browser UI (which is actually disabled by default in some browsers) and instead making your own.

    All it takes is a simple modal dialog with a form in, and you're all good. The only downside is that it won't be blocking anymore (if you can consider that a downside), so you need to put the rest of the code inside a callback that the prompt calls when it's closed.

    0 讨论(0)
  • 2021-01-25 13:17

    Short answer: no.

    Longer answer: No, but you can roll your own popups with jQuery's UI library or by hacking up something with the DOM yourself.

    0 讨论(0)
  • 2021-01-25 13:20

    No I don't believe so. The problem was that people would use prompts maliciously so microsoft added that to make it look more like it was a page specific prompt and not a IE prompt.

    You can do an in page dialog with jQuery or something:

    http://www.abeautifulsite.net/blog/2008/12/jquery-alert-dialogs

    0 讨论(0)
提交回复
热议问题