您的位置:首页 > Web前端 > JavaScript

javaScript弹窗

2015-11-17 17:01 483 查看
(1)警告框

模态对话框,只有关闭了才能继续操作

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
alert("I am an alert box!");
}
</script>
</head>
<body>

<input type="button" onclick="myFunction()" value="Show alert box">

</body>
</html>


(2)确认框

可以点击确定或取消。点击确定返回true,否则返回false

<!DOCTYPE html>
<html>
<body>

<p>Click the button to display a confirm box.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction()
{
var x;
var r=confirm("Press a button!");
if (r==true)
{
x="You pressed OK!";
}
else
{
x="You pressed Cancel!";
}
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>


(3)提示框

1. 用于提示用户在进入页面前输入某个值

2.当提示框出现后,用户需要输入某个值,然后点击确认或取消才能继续操作

3.点击确认,返回输入的值;点击取消,返回null

<!DOCTYPE html>
<html>
<body>

<p>点击按钮查看输入的对话框。</p>

<button onclick="myFunction()">点我</button>

<p id="demo"></p>

<script>
function myFunction()
{
var x;

var person=prompt("请输入你的名字","Harry Potter");

if (person!=null)
{
x="你好 " + person + "! 今天感觉如何?";
document.getElementById("demo").innerHTML=x;
}
}
</script>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: