<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <style type="text/css">
a{color:#000}
</style> <script type="text/javascript" > $(function(){
$("a").each(function(){ $(this).click(function(){
var index = $('a').index($(this))
$('a').not(index).css('color','#000');
$('a').eq(index).css('color','green');
})
})
})
</script>
</head><body>
<a href="#">1</a><a href="#">2</a><a href="#">3</a><a href="#">4</a></body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <style type="text/css">
a{color:#000}
</style> <script type="text/javascript" > $(function(){
$("a").each(function(){ $(this).click(function(){
var index = $('a').index($(this))
$('a').not(index).css('color','#000');
$('a').eq(index).css('color','green');
})
})
})
</script>
</head><body>
<a href="#">1</a><a href="#">2</a><a href="#">3</a><a href="#">4</a></body>
</html>
自己手动改改就可以了。如果是生成的页面,生成页面的时候把样式写上去就好了。
别写#哈 有4个不同的页面哈。你这样写 每次加载新的页面都绑定的click都没了
功能没实现啊 我连接改成 <a href="1.html">1</a><a href="2.html">2</a><a href="3.html">3</a><a href="4.html">4</a>这个4个页面代码都一样 就是不行 你这样绑定肯定不行哈 一定要判断当前url判断哈
{
//根据传来的index设置哪个标签选中
}那么每个页面加载前,可以调用setTab(1); setTab(2);....以此来选中当前标签或者你通过地址栏传值比如 1.html?tab=1 获取tab值,然后设置选中不过推荐使用第一种方式