html 怎么点击一个按钮弹出一个提示框

html-css020

html 怎么点击一个按钮弹出一个提示框,第1张

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html,输入问题基础代码。

2、在index.html中的<body>标签中,输入js代码:

function fun() {

alert('click success!')

}

3、浏览器运行index.html页面,此时点击按钮弹出了提示框。

1、最基本的弹出窗口代码

<SCRIPT LANGUAGE="javascript">

<!--

window.open ("page.html")

-- >

</SCRIPT> 

window.open ("page.html") 用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。

2、经过设置后的弹出窗口

<SCRIPT LANGUAGE="javascript">

<!--

window.open ("page.html", "newwindow", "height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no")&nbsp

->

</SCRIPT>

<SCRIPT LANGUAGE="javascript">js脚本开始;window.open 弹出新窗口的命令;"page.html" 弹出窗口的文件名;"newwindow" 弹出窗口的名字(不是文件名),非必须,可用空"代替;

3、用函数控制弹出窗口

<script LANGUAGE="JavaScript">

<!--

function openwin() {

window.open ("page.html", "newwindow", "height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")

}

-->

</script>

这里定义了一个函数openwin(),函数内容就是打开一个窗口。

4、同时弹出2个窗口

<script LANGUAGE="JavaScript">

<!--

function openwin() {

window.open ("page.html", "newwindow", "height=100, width=100, top=0, left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")

&nbsp

window.open ("page2.html", "newwindow2", "height=100, width=100, top=100, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")

}

-->

</script>

为避免弹出的2个窗口覆盖,用top和left控制一下弹出的位置不要相互覆盖即可。

5、主窗口打开文件1.htm,同时弹出小窗口page.html

<script language="javascript">

<!--

function openwin() {

window.open("page.html","","width=200,height=200")

}

-->

</script>

在HTML页面加入:

<script type="text/javascript">

if(confirm("你还没有登录喔?")) {

window.location.href='login.html'

}

</script>