Placing an input of type password in prompt box

后端 未结 2 2040
青春惊慌失措
青春惊慌失措 2020-12-06 23:14

Hello guys I know that is probably a stupid question but i had to be sure after all. Can i add an input of type password in a prompt box? prompt box is a one of javascript\

相关标签:
2条回答
  • 2020-12-06 23:26

    No, you can't.

    The popup is browser controlled and can't be changed.

    As the documentation shows, you can only supply a message and default text.


    You can use javascript to create your own overlay that simulates a prompt popup.

    See the jQuery UI Dialog for ideas and examples.

    0 讨论(0)
  • 2020-12-06 23:29

    If you literally mean the prompt function, you can't. What you can do instead is pop up a div or similar above the main content of your page (using absolute positioning and a z-index value) and put the password box in there.

    More in the various answers to these questions:

    • How to have a JQUERY POPUP window by using only JQUERY (without other extra JS)
    • Making a Javascript Yes/No Confirmation Box?

    There are a variety of libraries you can use that will do the hard work for you (not that it's that hard, but still). If you're already using a library like jQuery, Prototype, YUI, Closure, or any of several others, you may find that there's a plug-in designed for use with that library (jQuery UI for jQuery, for instance). If not, there are plenty of stand-alone implementations. Look for "light box" or "lightweight window" or "JavaScript dialog box", etc.

    Note that any of these will require a bit of a change to the logic of your code, since prompt brings the browser and your script to a screeching halt until the prompt is dismissed by the user, whereas this mechanism of flying an element over the top of the content is, by its nature, asynchronous.

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