JavaScript打开链接

来源:互联网 发布:怪物猎人p2g武器数据 编辑:程序博客网 时间:2024/05/16 15:13

<a href="javascript:;" onClick="javascript:window.open('admin_fk.asp?id=')"> 文字部分</a>

 

<a href="#"onclick="del(id)">删除</a>会出现不正常跳转,将

#改成javascript:void(0)就可以了

#包含了一个位置信息

默认的锚点是#top 也就是网页的上端

而javascript:void(0)  仅仅表示一个死链接

这就是为什么有的时候页面很长浏览链接明明是#可是

跳动到了页首

而javascript:void(0) 则不是如此

所以调用脚本的时候最好用void(0)

或者<input onclick>

<div onclick>等

打开新窗口链接的几种办法

1.window.open('url')

2.用自定义函数

<script type="text/javascript">

 function del(consumer_id){
  window.location.href="<%=basePath%>datamaintainservlet?command=consumerDel&consumer_id="+consumer_id;
 }

</script>

正解:

<a href="javascript:void(0)" onclick="del(${consumer_id})">删除</a>

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zjx2388/archive/2009/02/20/3913547.aspx

 

Button链接,代码如下:

1.链接到某页
<input type="button" name="Submit" value="确 定" class="btn" onclick="location.href='filename.html'" />

2.返回(等同后退)
<input name="Submit2" type="button" class="btn" onclick="location.href='javascript:history.go(-1);'" value="返 回" />

3.打开新网页
<input type="button" name="Submit2" value="确 定" class="btn" onclick="window.open('filename.html')" />

4.
打开无边框的新窗口
<input type="button" name="Submit2" value="确 定" class="btn" onclick="javascript:window.open('filename.html','','width=720,height=500,resizable=yes,scrollbars=yes,status=no')" />

5.
打开新网页同时指向另一页
<input type="button" name="Submit2" value="确 定" class="btn" onclick="window.open('filename.html');location.href='http://hi.baidu.com/harryxue'" />

6.打开无边框的新窗口同时指向另一页
<input type="button" name="Submit2" value="确 定" class="btn" onclick="javascript:window.open('http://hi.baidu.com/harryxue','','width=720,height=500,resizable=yes,scrollbars=yes,status=no'); window.location='filename.html';" />

7.点击按钮弹出确认alert窗口
方式一:
<input type="button" name="Submit1" value="确定" class="btn"
onClick="alert('是否确认提交?');location.href= 'filename.html';return false;" >
方式二:
<input type="button" name="Submit2" value="确定" class="btn"
onClick="if (confirm('是否确认提交?'))location.href= 'filename.html';return false;" >

 ===========================

<input   type=button   value=刷新   onclick="window.location.reload()"> 
  <input   type=button   value=前进   onclick="window.history.go(1)"> 
  <input   type=button   value=后退   onclick="window.history.go(-1)"> 
  <input   type=button   value=前进   onclick="window.history.forward()"> 
  <input   type=button   value=后退   onclick="window.history.back()">

原创粉丝点击