当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() { /