html中的a标签用js来实现页面跳转的功能(php分页时做的页面跳转)

本文介绍了在PHP分页场景下,如何利用JavaScript实现页面跳转。通过包裹a标签的图片,结合onclick事件,调用page()函数实现用户输入页码的跳转。当a标签的href为空时,浏览器不会执行跳转,解决方案是设置href为"javascript:page();"或"javascript:;"并结合onclick事件。
摘要由CSDN通过智能技术生成

当php在做分页时,有时候会要想做个指定跳转到某页的功能,而要跳转到某页就要涉及到js。因为必须通过js来找到用户输入的是什么,是哪一页。

所以,如果你用的是一个图片来做点击实现跳转的话,那么就可以通过在图片外面包裹一个a标签来实现点击并获取输入值。

  现在问题是这样写:

<a href="" οnclick=“page()”>那么浏览器中是不能实现跳转的呢。因为page()的js方法中不管你怎么写Windows.location.href="www.zhishuibei.com";都不能跳转,原因是a标签的href里面是空的,浏览器执行了这个地方。那么怎么办呢?

  其实写程序久了就容易忘了html里面的一些常识。呵呵。那么问题怎么解决呢?看下面:

<a href="javascript:page();">现在去试试呢。或者:

<a href="javascript:;" οnclick="page()">

也去试试呢。没有浏览器兼容的问题吧。呵呵。就这么简单。只是因为忘了一些HTML常识而已。

下面是我的页面源码,共享出来给大家:

blog.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--

Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Title      : Simpleton 
Version    : 1.0
Released   : 20110315
Description: A two-column web design, best for your personal and business blogging.

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>GayaYang的个人博客---首页</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="/css/xp1980.css" />
<script type="text/javascript" src="/css/xp1980.js"></script>
<style type="text/css">
/*
a{color:blue}
 body {	margin: 0; padding: 0;
	/*font: 10px normal Verdana, Arial, Helvetica, sans-serif;
	background: #fff; }
img {border: none;}
ul,li{list-style: none;}
*/
#menu_out{width:964px;background:url(/images/menu_left.gif) no-repeat left top;margin:5px auto;}
#menu_in{background:url(/images/menu_right.gif) no-repeat right top;padding-right:4px;}
#menu{height:46px;}
#menu ul{padding:0;border:0;list-style:none;line-height:150%;margin-left:4px;}
#topnav ul{font-size: 14px;float: left;}
#topnav li{width:119px; overflow: hidden; float: left; height:46px;}
#topnav a, #topnav span {width:119px;padding:11px 0;text-align:center;float: left; text-decoration: none; color: #fff;text-transform: uppercase;clear: both;height: 24px;line-height: 24px;font-size: 14px;}

#topnav span{background: url(/images/a_bg.gif) repeat-x left top;}
#topnav a{color: #000;background: url(/images/a_bg.gif) repeat-x left bottom;}

#pages{
	border:1px solid #939393;
    font-size:14px;
    margin:5px 5px;
    padding:1px 8px;
}
#pagea a:hover{
	background-color:#103C5D;
    color:white;
}
</style>
<script type="text/javascript" src="/images/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {	
	$("#topnav li").prepend("<span></span>"); //Throws an empty span tag right before the a tag
	$("#topnav li").each(function() { /
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值