>  기사  >  웹 프론트엔드  >  JS弹出对话框实现方法(三种方式)_javascript技巧

JS弹出对话框实现方法(三种方式)_javascript技巧

WBOY
WBOY원래의
2016-05-16 15:24:452526검색

本文实例讲述了JS弹出对话框实现方法。分享给大家供大家参考,具体如下:

1.警告框

<html>
<head>
<script type="text/javascript">
function disp_alert()
{
alert("我是警告框!!")
}
</script>
</head>
<body>
<input type="button" onclick="disp_alert()" value="显示警告框" />
</body>
</html>

2.确定取消框

<html>
<head>
<script type="text/javascript">
function disp_confirm()
{
var r=confirm("按下按钮")
if (r==true)
  {
  document.write("您按了确认!")
  }
else
  {
  document.write("您按了取消!")
  }
}
</script>
</head>
<body>
<input type="button" onclick="disp_confirm()" value="显示确认框" />
</body>
</html>

3.有输入的框

<html>
<head>
<script type="text/javascript">
function disp_prompt()
{
var name=prompt("请输入您的名字","Bill Gates")
if (name!=null && name!="")
  {
  document.write("你好!" + name + " 今天过得怎么样?")
  }
}
</script>
</head>
<body>
<input type="button" onclick="disp_prompt()" value="显示提示框" />
</body>
</html>

希望本文所述对大家JavaScript程序设计有所帮助。

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.