非突兀的Javascript弹出窗口

时间:2013-01-15 03:16:35

标签: javascript html popup alert

如何在javascript中创建弹出/警报以显示信息,同时允许用户在HTML表单的输入字段中输入数据。

1 个答案:

答案 0 :(得分:2)

http://jsfiddle.net/rwVGt/

HTML:

<p>testingtestingtestingtestingtestingtestingtestingtestingtest ingtestingtestingtestingtestingtestingtestingtestingtestingt
  estingtestingtestingtestingtestingtestingt estingtestingtestingtestingtestingtesting</p>
<input
type="button" value="click for popup" onClick="popup()" />

CSS:

#pop
{
  width: 200px;
  height: 200px;
  border: solid 1px #000;
  margin-top: -30px;
  margin-left: 20px;
  position: fixed;
  background-color: #fff;
}

使用Javascript:

window.onload = function () {
  var popup = document.createElement("div");
  var text = document.createTextNode("blah blah blah");
  popup.appendChild(text);
  popup.style.visibility = "hidden";
  popup.id = "pop";
  document.getElementsByTagName("body")[0].appendChild(popup);
};

window.popup = function () {
  var pop = document.getElementById("pop");
  pop.style.visibility = "visible";
  window.setTimeout(function(){document.getElementById("pop").style.visibility="hidden";},1000);
};