如何自定义 JavaScript 提示?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9193333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:53:43  来源:igfitidea点击:

How to customize the JavaScript prompt?

javascript

提问by Sillicon.Dragons

I am trying to use the JavaScript prompt for entering text that will be enclosed between tags e.g

我正在尝试使用 JavaScript 提示输入将包含在标签之间的文本,例如

[url]http://www.yahoo.com[/url]

[网址]http://www.yahoo.com[/url]

The problem is that the prompt always appear in the top left corner of the browser.

问题是提示总是出现在浏览器的左上角。

How do I position such that it only display the prompt around the text area where the text will be entered?

如何定位,使其仅在将输入文本的文本区域周围显示提示?

And also how do I customize the JavaScript prompt so that it look more user friendly?

以及如何自定义 JavaScript 提示以使其看起来对用户更友好?

回答by zozo

You can't customize that (if you are refering at prompt()). You need to create a pop up window and customize its insides.

您无法自定义(如果您在 prompt() 处引用)。您需要创建一个弹出窗口并自定义其内部。

回答by LeonardChallis

You can't position the JavaScript prompt box, and you'll find it varies between different browsers.

您无法定位 JavaScript 提示框,您会发现它因浏览器而异。

Although you didn't explicitly ask, may I suggest either creating your own prompt (as simple as making a div with an input and positioning absolutely, and setting the display CSS property correctly to "pop" it up and close it, or (and this is what I would do) use something like jQueryUI or a similar alternative that will do what you want.

尽管您没有明确询问,我是否可以建议您创建自己的提示(就像使用绝对输入和定位制作 div 一样简单,并正确设置显示 CSS 属性以“弹出”并关闭它,或者(和这就是我会做的)使用类似 jQueryUI 或类似的替代品来做你想做的事。

One final bonus: just insert the [url][/url] tags with a placeholder domain or message imbeteen, and automatically highlight it and give it focus, so that when they start typing it will appear there, inline.

最后一个好处:只需插入带有占位符域或消息 imbeteen 的 [url][/url] 标签,并自动突出显示它并给它焦点,这样当他们开始输入时,它就会出现在那里,内联。

回答by mplungjan

Here is an accepted way:

这是一种公认​​的方式:

http://jqueryui.com/demos/dialog/

http://jqueryui.com/demos/dialog/