开发者

Placing an input of type password in prompt box

Hello guys I kno开发者_Python百科w 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's Popup boxes.(Alert,Confirm and Prompt)


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜