2012-06-14 31 views
0

我已經使用HTML/CSS和Java腳本創建了一個按鈕。該按鈕應該指示某人到不同的頁面,但它不起作用。它適用於Chrome和Safari,但不適用於Firefox。按鈕不會在Firefox或IE中點擊

任何人都可以幫助代碼,以便它可以在Firefox和IE?

謝謝。

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

<html> 

<head> 
    <title>WTF</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
</head> 

<style type="text/css"> 


button{ 
color:#08233e; 
font:2.4em Futura, ‘Century Gothic’, AppleGothic, sans-serif; 
font-size:70%; 
padding:14px; 
background:url(overlay.png) repeat-x center #ffcc00; 
background-color:rgba(255,204,0,1); 
border:1px solid #ffcc00; 
-moz-border-radius:10px; 
-webkit-border-radius:10px; 
border-radius:10px; 
border-bottom:1px solid #9f9f9f; 
-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5); 
-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5); 
box-shadow:inset 0 1px 0 rgba(255,255,255,0.5); 
cursor:pointer; 
} 

button:hover{background-color:rgba(255,204,0,0.8);} 

</style> 

<body> 

<button><a href="http://www.ihatelebronjames.com" class="button1">LEBRON IS A NO-GOOD, BACK-STABBING, AFRAID-OF-THE-MOMENT CHOKE ARTIST!</a></button><br> 
<button><a href="http://www.lebronjames.com" class="button2">LEBRON IS THE PINNACE OF BASKETBALL PERFECTION!</a></button>    


</body> 

</html> 

回答

2

一個非常簡單的解決方法是:

<a href="http://www.lebronjames.com" class="button2"><button>LEBRON IS THE PINNACE OF BASKETBALL PERFECTION!</button></a> 

把按鈕標籤的標籤

另一個(和更好的做法)的內部選項:

http://jsfiddle.net/a6seL/

這裏我們只需將一個類「button2」添加到<a>。然後,我們按照<button>的樣式進行設計,但要真正獲得按鈕外觀,我們還要將display : block添加到課程中。

現在你只需要<a>而不再需要<button>

請參閱我的jsfiddle。

+0

看起來像它的作品。正如我試圖學習,你能解釋爲什麼這個工程? –

0

我認爲,如果你換按鈕它將正常外錨,雖然我不知道如何實現有效的油墨按鈕

1

使用或者一個鏈接或按鈕 100%。混合兩者並沒有意義。如果你想要一個鏈接,請使用鏈接。如果你想要一個按鈕,使用一個按鈕。

僅用於造型目的使用按鈕(或任何其他元素)是非常糟糕的做法。調整您的CSS到您的語義,有意義的HTML。

此外,在XHTML 1.0,你根本無法把一個<a><button>

<!-- button uses %Flow; but excludes a, form and form controls --> 

<!ENTITY % button.content "(#PCDATA | p | %heading; | div | %lists; | %blocktext; | 
    table | %special; | %fontstyle; | %phrase; | %misc;)*"> 

the XHTML 1.0 Transitional DTD(您正在使用)

0

你不能做到這一點,按鈕是不是重定向,你可以創建一個鏈接,並使它看起來像一個CSS按鈕,或者你可以創建一個按鈕,並給它JS功能,如下所示:

<button onclick="self.location=('http://www.ihatelebronjames.com');">LEBRON IS A NO-GOOD, BACK-STABBING, AFRAID-OF-THE-MOMENT CHOKE ARTIST!</a></button><br> 
<button onclick="self.location=('http://www.lebronjames.com');">LEBRON IS THE PINNACE OF BASKETBALL PERFECTION!</a></button>