在javascript中定位提示弹出窗口 [英] positioning the prompt popup in javascript

查看:137
本文介绍了在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中定位提示弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆