开发者

Native (non-jqueryui) way to set prompt() input field inline

开发者 https://www.devze.com 2022-12-26 12:28 出处:网络
I might just be using the wrong keywords on Google, but what I have in mind is: --------------------------------

I might just be using the wrong keywords on Google, but what I have in mind is:

 --------------------------------
|    What is your mailbox?       |
|                                |
|    [       ]@mail.example.org  |
|                                |
|        [OK]      [Cancel]      |
 --------------------------------

The idea being that the input field is followed right behind by the mail server name, to help avoid instances where:

  1. If I don't make it follow right behind, the user puts in the whole thing,

  2. If I default it to "blah@mail.example.org" they delete the server name.

In either case, it's not too big a deal, as I will know that if the returned value does have the server, to remove 开发者_Go百科it and if doesn't, I know what server it belongs to, but I think this visual aid will be a better user experience and lower the amount of validation worries I tend to get.


If the user deletes the host and doesn't specify their own host, you can assume that they intended the default host.

var email = prompt("What is your email address?", "@mail.example.org");
if (email.indexOf("@") === -1) {
  email += "@mail.example.org";
}


You can set a default value in the standard Javascript prompts, but you can't do much more than that. I would just check afterwards and strip or add the server part as needed.

0

精彩评论

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

关注公众号