在javascript中定位提示弹出窗口

编程入门 行业动态 更新时间:2024-10-25 10:34:31
本文介绍了在javascript中定位提示弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个像下面这样的javascript提示,我想带上屏幕的提示中心。如何在使用javascript时执行此操作?

i have a javascript prompt like the following and i would like to bring the prompt center of the screen. How to do this in using javascript?

function showUpdate() { var x; var name=prompt("Please enter your name",""); if ( name != null ) { x="Hello " + name + "! How are you today?"; alert("Input : " + name ); } }

这就是我怎么称呼这个:

And this is how i call this :

<a onclick = "showUpdate() " style="vertical-align: middle;" class="parent" href=""><span>5. Missed P/U Comments</span></a>

它可以找到除了提示转到 IE的左下角并居中 Firefox 但我需要相同的解决方案才能在两种浏览器中使用。

it works find excepts the prompt goes to the left corner in IE and center in Firefox but i need to the same solution to work in both the browsers.

推荐答案

提示符(以及 alert )弹出窗口已实现根据您使用的浏览器而有所不同。这是因为弹出窗口是浏览器功能,它们不是JavaScript对象或类似的东西。 (就像每个浏览器的控制台不同,它取决于实现。)

The prompt (and alert) popups are implemented differently depending on the browser you're using. This is because the popups are browser functionalities, they aren't JavaScript objects or anything like that. (Just like the console is different for each browser, it depends on the implementation.)

如果你真的想要一致地定位/设置你的提示,你就会去必须建立自己的提示。

If you really want your prompts to be positioned / styled consistently, you're going to have to build your own prompt.

最简单的方法是使用像 jQueryUI 。

The easy way out would be to use a library like jQueryUI.

另一方面,你可以自己构建它:

On the other hand, you can just build it yourself:

document.getElementById('showPromptButton').addEventListener('click', showSprompt); document.getElementById('promptButton').addEventListener('click', submitPrompt); var prompt = document.getElementById('myPrompt'); var promptAnswer = document.getElementById('promptAnswer'); function showSprompt() { promptAnswer.value = ''; // Reset the prompt's answer document.getElementById('promptQuestion').innerText = "What's your question?"; // set the prompt's question prompt.style.display = 'block'; // Show the prompt } function submitPrompt() { var answer = promptAnswer.value; // Get the answer prompt.style.display = 'none'; // Hide the prompt console.log(answer); }

#myPrompt{ display:none; /* Style your prompt here. */ }

<input id="showPromptButton" type="button" value="Show Prompt" /> <div id="myPrompt" class="proptDiv"> <span id="promptQuestion"></span> <input id="promptAnswer" type="text" /> <input id="promptButton" type="button" value="Submit" /> </div>

更多推荐

在javascript中定位提示弹出窗口

本文发布于:2023-08-06 04:42:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310135.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出窗口   提示   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!