如何在javascript中创建弹出/警报以显示信息,同时允许用户在HTML表单的输入字段中输入数据。
答案 0 :(得分:2)
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);
};