我有ff.code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Videos</title>
<link href="normal.css" rel="stylesheet" /><script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
$('.videos').click(function(){
//window.demo.logSectionVisit( "Visited Videos Section" );
$(location).attr('href',"google.com");
//alert(0);
//window.location.href = "http://stackoverflow.com";
});
});
</script>
</head>
<body>
<div id="buttons">
<div id="buttonsleft">
<a href="reset.html" class="reset"><div class="buttonlabel">New Session</div></a>
</div>
<div id="buttonsright">
<a href="" class="videos"><div class="buttonlabel">Videos</div></a>
<a href="" class="slideshows"><div class="buttonlabel">Slide Shows</div></a>
<a href="" class="forms"><div class="buttonlabel">Forms</div></a>
<a href="" class="surveys"><div class="buttonlabel">Surveys</div></a>
<a href="" class="websites"><div class="buttonlabel">Websites</div></a>
<a href="" class="interactive"><div class="buttonlabel">Interactive</div></a>
<a href="" class="admin"><div class="buttonlabel">Admin</div></a>
</div>
</div>
<div id="mainbody">
<div id="links2">
</div>
</div>
</body>
</html>
我想知道为什么当我点击视频按钮时,它不会重定向。任何想法?
答案 0 :(得分:2)
尝试取消注释该行:
// window.location.href =“http://stackoverflow.com”;
并评论该行:
$(位置).attr( 'href' 属性, “google.com”);
答案 1 :(得分:1)
而不是
<a href="" class="videos"><div class="buttonlabel">Videos</div></a>
试
<div class="buttonlabel videos">Videos</div>
答案 2 :(得分:1)
除了Andrew建议的内容之外,如果您需要拥有锚标记,请从锚点中删除href属性,或者将preventDefault()
添加到点击处理程序中:
$('.videos').click(function(e){
// note that if you redirect to google.com only, it a relative redirect...
// so to go to the actual www.google.com site, use the full url
$(location).attr('href',"http://www.google.com");
e.preventDefault();
});