2012-10-25 31 views
1

每當我嘗試,我得到在Firefox的控制檯以下錯誤:JavaScript就無法工作:編碼錯誤在Firefox

[09:20:30.028] HTML文檔的字符編碼未聲明。如果文檔包含US-ASCII範圍之外的字符,則該文檔將在某些瀏覽器配置中呈現亂碼文本。頁面的字符編碼必須在文檔或傳輸協議中聲明。

<!DOCTYPE html> 
<html> 
<head> 
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> 
<meta content="utf-8" http-equiv="encoding"> 
<title>this is a title</title> 
<link rel="stylesheet" type="text/css" href="style.css" /> 
<script> 
function showAnswer(){ 
    document.getElementById("ans").innerHTML="This is the answer"; 
} 
</script> 
</head> 
<body> 
<div id="q"> 
This is a question? 
<button action="showAnswer()">Show Answer</button> 
</div> 
<div id="ans"> 
</div> 
</body> 
</html> 

對不起,如果這是一個愚蠢的問題,我還挺新的。

+1

也許是因爲你聲明的編碼兩次? – sgroves

+0

'

+0

取出其中一個後,它仍然不起作用 – Sabreok

回答

3

你只需要;

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

應該解決您的問題。

+0

我仍然收到錯誤... – Sabreok

+1

請參閱Alex對'onclick'的回答。應該讓它爲你工作 – JPK

1

擺脫

<meta content="utf-8" http-equiv="encoding"> 

你只是想......

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

這也是錯誤的...

<button action="showAnswer()">Show Answer</button> 

可能想...

<button type="button" onclick="showAnswer()">Show Answer</button> 

http://jsfiddle.net/5Qtq2/

相關問題