javascript怎么通过按钮跳转跳转新页面

JavaScript012

javascript怎么通过按钮跳转跳转新页面,第1张

按钮添加点击事件 然后在点击事件中利用js跳转

JS跳转大概有以下几种方式:

第一种:(跳转到b.html)

<script language="javascript" type="text/javascript">

window.location.href="b.html"

</script>

第二种:(返回上一页面)

<script language="javascript">

window.history.back(-1)

</script>

第三种:

<script language="javascript">

window.navigate("b.html")

</script>

第四种:

<script language="JavaScript">

self.location=’b.html’

</script>

第五种:

<script language="javascript">

top.location=’b.html’

</script>

javascript中的location.href有很多种用法,主要如下:

self.location.href="/url" 当前页面打开URL页面

location.href="/url" 当前页面打开URL页面

windows.location.href="/url" 当前页面打开URL页面,前面三个用法相同

this.location.href="/url" 当前页面打开URL页面

parent.location.href="/url" 在父页面打开新页面

top.location.href="/url" 在顶层页面打开新页面

点击按钮怎么跳转到另外一个页面呢?我们在网站制作中可能是需要的,因为有时我们需要做这样的效果,尤其是将按钮做成一个图片,而点击图片要跳转到新的页面时,怎么做到呢?

这样的效果可以:onclick="window.location='新页面'"

来实现。

1.在原来的窗体中直接跳转用

代码如下

window.location.href="你所要跳转的页面"

2、在新窗体中打开页面用:

代码如下

window.open('你所要跳转的页面')

window.history.back(-1)返回上一页

代码如下

<input

type="submit"

name="Submit"

value="同意"

onclick=window.open(http://www.jb51.net/)>

如果要在点击按钮提交时验证输入款是否填入了内容,要怎么做呢?当用户名输入或者其它的为空的时候,点击按钮不提交,可以按下列的方法做。

代码如下

复制代码

代码如下:

<input

type="submit"

name="submit"

onclick="open()">

<script

language=javascript>

fuction

open(){

if(!document.form_name.username.value)

{

alert("请输入用户名!")

document.form_name.username.focus()

return

false

}else

document.form_name.action="aaa.htm"

}

</script>