javaScript弹窗

(1)警告框

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

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

<input type="button" οnclick="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 οnclick="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 οnclick="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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值