2011-06-17 70 views
0

我有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> 

我不知道爲什麼,當我點擊視頻按鈕,它不重定向。有任何想法嗎?取而代之的

<a href="" class="videos"><div class="buttonlabel">Videos</div></a> 

+0

感謝您的答覆傢伙:) – Kris 2011-06-17 02:06:10

回答

1

此外什麼安德魯暗示,如果你需要有錨標記,無論是從錨卸下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(); 
}); 
+0

這是行不通的 – Kris 2011-06-17 02:04:59

+0

這裏是完整的工作示例:http://jsbin.com/ikayu3/edit無論如何Andrerws是更好的解決方案/答案。 – Jaime 2011-06-17 02:12:49

+0

太酷了!這對我有用。 :) – Kris 2011-06-17 02:21:16

1

嘗試

<div class="buttonlabel videos">Videos</div> 
+0

這很接近,非常感謝,我從來不知道它可能在一個div中有兩個類! :) – Kris 2011-06-17 02:05:35

2

嘗試取消對該行:

//window.location.href = 「http://stackoverflow.com」;

和註釋行:

$(位置).attr( 'href' 屬性, 「google.com」);

+0

我試過了,它不起作用 – Kris 2011-06-17 02:04:47

+0

之後,我建議你應該用window.location.replace來替代window.location.href,因爲它可以讓父頁面不再出現在瀏覽器歷史記錄中,避免了永無止境的循環。 – 2011-06-17 02:07:05

+2

試試這個window.location.replace(「http://stackoverflow.com」); – 2011-06-17 02:08:03