2013-07-07 161 views
-2

無論出於何種原因,我不能讓下面的代碼在IE9在所有的工作工作,但在Firefox,Chrome和歌劇作品:代碼與Internet Explorer 9

<!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>Laughing Man Productions²-Administrator Portal</title> 

<!--[if !IE 9]> <!--><link rel="stylesheet" type="text/css" href="http://www.lmpgames.com/WEB401/W2/css/login_page.css"/><!--<![endif]--> 

<!--[if IE 9]> 
<link rel="stylesheet" type="text/css" href="http://www.lmpgames.com/WEB401/W2/css/login_page_IE.css"/> 
<![endif]--> 


</head> 

<body> 
<div class="login_bg"> 
    <form action="" method="post" enctype="multipart/form-data"> 
    <fieldset class="fset"> 
     <div class="username_text"> 
     Username/Email Address: 
      <span class="username_field"> 
      <input name="txtbUName" type="text" style="background-color:#DDDDDD;" value="Username" size="20" maxlength="60" /> 
      </span> 
     </div><br/> 

     <div class="password_text"> 
     Password: 
      <span class="password_field"> 
      <input name="txtbPWord" type="password" style="background-color:#DDDDDD;" value="Password" size="20" maxlength="16" /> 
      </span> 
     </div><br/> 

     <div class="sub"> 
     <input name="btnSubmit" type="button" onclick="formatUName(this.form)" value="Submit" /> 
     </div> 

     <textarea name="txtaFOutput" class="txta" cols="1" rows="1"> 

     </textarea> 
    </fieldset> 
    </form> 
    </div> 



<script type="application/javascript"> 
    function formatUName(form) 
    { 
     //Set up variables and references for use later on 
     var button = form.btnSubmit; 
     var txta = form.txtaFOutput; 
     var username = form.txtbUName; 
     var password = form.txtbPWord; 
     var uName = "default"; 
     var pWord = ""; 

     uName = username.value; //Obtain the value of the username field on submit 

     //Then remove spaces from the value and change all letters to uppercase 
     uName = uName.replace(/\s+/g, '');  
     uName = uName.toUpperCase(); 

     //Finally print the formatted username to the textarea 
     txta.value = uName + " is your username";  
    } 
</script> 


</body>  
</html> 

當我加載網頁起來IE並單擊提交沒有任何反應。我試圖將.value更改爲innerHTML和innerText,但它們都不在IE中工作。

編輯:

與IE擺弄周圍後我終於設法得到調試運行,它吐出來,這樣的錯誤:

Line: 23 Error: Unable to get value of the property 'appendChild': object is null or undefined

編輯2:

忽略前面的錯誤。 IE允許Vuze通過我不知道Vuze安裝的插件注入Javascript代碼。禁用它們,現在新的錯誤消息,是關於我的函數名稱:

Line 35: The value of the property 'formatUName' is null or undefined, not a Function object

+2

你的註釋語法是明確錯誤。使用'//'作爲行註釋 – Bergi

+0

你在IE中遇到任何錯誤嗎?你有沒有試過調試它,直到它的部分工作? – Bergi

+0

@Bergi更改評論標籤反斜槓沒有改變。至於調試我不能。根據IE的開發工具,我的函數沒有可執行代碼,因此腳本標記中的斷點是無效的。 – Geowil

回答

1

當我運行這個在IE中,JavaScript的正常工作,但形式不提交。如果這是你所面臨的問題,原因是:

<input name="btnSubmit" type="button" onclick="formatUName(this.form)" value="Submit" /> 

變化type="button"type="submit"。當缺少明確的提交按鈕的表單中有type="button"時,瀏覽器行爲是不可預知的。

+0

更改類型提交後,代碼仍然不適用於我。 – Geowil

+1

當你說「它不工作」時,什麼是,什麼不發生? JavaScript是否被執行?表單是否提交?嘗試在JavaScript函數中添加alert(「foo」);'來查看它是否被執行。 –

+0

當我點擊提交按鈕時,什麼都沒有發生。無法放置中斷,因爲IE在腳本標記中看不到可執行代碼。看到我原來的問題,錯誤消息我能夠讓IE瀏覽器吐出來對我。 – Geowil

0

在HTML中,<!-- comment -->是評論的正確語法。

另一方面,Javascript使用ANSI C標準註釋// comment/* comment */

你需要改變:

function formatUName(form) 
{ 
    <!-->Set up variables and references for use later on 
    var button = form.btnSubmit; 
    var txta = form.txtaFOutput; 
    var username = form.txtbUName; 
    var password = form.txtbPWord; 
    var uName = "default"; 
    var pWord = ""; 

    uName = username.value; <!--> Obtain the value of the username field on submit 

    <!--> Then remove spaces from the value and change all letters to uppercase 
    uName = uName.replace(/\s+/g, '');  
    uName = uName.toUpperCase(); 

    <!--> Finally print the formatted username to the textarea 
    txta.value = uName + " is your username"; 
} 

要:

function formatUName(form) 
{ 
    // Set up variables and references for use later on 
    var button = form.btnSubmit; 
    var txta = form.txtaFOutput; 
    var username = form.txtbUName; 
    var password = form.txtbPWord; 
    var uName = "default"; 
    var pWord = ""; 

    uName = username.value; // Obtain the value of the username field on submit 

    // Then remove spaces from the value and change all letters to uppercase 
    uName = uName.replace(/\s+/g, '');  
    uName = uName.toUpperCase(); 

    // Finally print the formatted username to the textarea 
    txta.value = uName + " is your username"; 
} 
+0

你說得對,Geowil應該糾正他的評論語法,但是當我運行他的代碼時,IE似乎並沒有窒息。 –

+0

如上所述,更改評論標籤並沒有解決問題。 – Geowil

0

多選了拼圖的碎片。起初,我得到的錯誤是由於一個Vuze插件,IE允許將Conduit Javascript注入到我的所有網頁中。第二個錯誤是Internet Explorer本身並沒有理由被竊聽。

在測試代碼開始工作時停止響應後重新啓動IE後,差不多。仍然有一個問題,這是由納撒尼爾建議將btnSubmit從一種按鈕更改爲一種提交。這導致我的所有瀏覽器中的代碼停止工作;文本區域不會正確更新其值。

改變類型回按鈕的代碼在所有測試的瀏覽器後:IE9 /火狐18.1 /歌劇12.15 /鉻28

+0

歌劇9沒有人再使用它,更新到版本12! – Bergi

+0

@Bergi其實它是12. 12.15。雖然可以發誓它是9。我必須更新它並忘記。 – Geowil