2013-04-27 105 views
0

我使用twitter引導來編寫以下內容以進行驗證,如果錯誤應該更改helptext並更改類名稱,但它看起來不會改變結果。紅)。更改classname但不反映結果

提示結果爲alert alert-error

我該如何解決? Thx提前。

HTML

<label>Account</label> 
<input id="stdAccount" name="account" type="text" value="" class="input-xlarge" onblur="validateAccountAndID(this,document.getElementById('stdAccountHelp'));">  
<div class="" id="stdAccountHelp"></div> 

JS

function validateAccountAndID (inputField, helpText) { 
    if(!validateNonEmpty(inputField, helpText))return false; 
    else { 
     var regex = /^\d{1,10}$/; 
     if(!regex.test(inputField.value)){ 
      helpText.classname = 'alert alert-error'; 
      helpText.innerHTML = "Only allow <= 10 numbers!"; 
      alert(helpText.classname); 
      return false; 
     } 
    } 
     helpText.classname = ''; 
     helpText.innerHTML = ""; 
     return true;  
} 
+0

不引導需要jQuery?你爲什麼不把它用於這種事情? – Ian 2013-04-27 18:51:00

+2

不應該是helpText.className(大寫N)嗎? – 2013-04-27 18:51:59

+0

我沒有學過jQuery,我已經學習了一些JavaScript,所以我使用它。 – 2013-04-27 18:54:37

回答

2

我覺得應該是:

helpText.className = 'alert alert-error'; 

className是獲取屬性/設置類DOM元素,而不是classname