2012-12-04 17 views
1

不工作,我需要進入我們的Web腳本冒號或管道停止用戶,我使用這段代碼:在Chrome中使用字符檢測;在Firefox

} 
function colonFilter(evt) 
{ 
    var e = event || evt; 
    var charCode = e.which || e.keyCode; 

    if (charCode == 58 || charCode == 124) 
    return false; 

    return true; 

} 

它工作在Chrome罰款,然而,當我訪問該網站在Firefox中不起作用。我做錯了什麼?

+1

我不知道究竟「它不工作」的意思。 – Pointy

+0

當我使用chrome時,它會阻止輸入,但Firefox仍然允許我輸入冒號或管道。 – user1875964

+0

您是否在瀏覽器控制檯中看到錯誤?你有沒有檢查過Firefox中實際存在的charCode? (使用'console.log(charCode)') – Pointy

回答

0

您沒有將事件對象傳遞給函數。 Chrome模仿Internet Explorer並維護全球「事件」; Firefox不。

<input name="description" type="text" onkeypress="return colonFilter(event);" size="60" maxlength="255" value=""> 

這將適用於所有瀏覽器。

相關問題