2016-12-12 72 views
0

在Firefox中,如果我在MVC View中選擇了控件,Tab鍵不起作用。它不會去下一個控制。Tab鍵在Firefox中的JavaScript中不起作用MVC

function onlyAlphabets(e, t) { 
 
     try { 
 
      if (window.event) { 
 
       var charCode = window.event.keyCode; 
 
      } 
 
      else if (e) { 
 
       var charCode = e.which; 
 
      } 
 
      else { return true; } 
 
      if (charCode == 9 || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123)) 
 
       return true; 
 
      else 
 
       return false; 
 
     } 
 
     catch (err) { 
 
      alert(err.Description); 
 
     } 
 
    }
@Html.TextBoxFor(model => model.FirstName, new { @class = "form-control", @placeholder = "First Name", @id = "txtFirstName", @maxlength = "50", onkeypress = "return onlyAlphabets(event,this);" }) 
 
@Html.TextBoxFor(model => model.LastName, new { @class = "form-control", @placeholder = "Last Name", @id = "txtLastName", @maxlength = "50", onkeypress = "return onlyAlphabets(event,this);" })

+0

它在任何其他瀏覽器?您是否嘗試過記錄charCode,以確保按下按鈕(可能是9)時它是您所期望的? – ADyson

+0

是的,它在其他瀏覽器中工作。我把警報捕獲charCode,它顯示0而不是9,所以它是在其他部分。 – kkakadiya

+1

這可能有助於http://stackoverflow.com/questions/4793233/capturing-the-tab-key-using-javascript-in-firefox – ADyson

回答

0

function onlyAlphabets(e, t) { 
 
     try { 
 
      if (window.event) { 
 
       var charCode = window.event.keyCode; 
 
      } 
 
      else if (e) { 
 
       var charCode = e.which; 
 
      } 
 
      else { return true; } 
 
      if (charCode == 9 || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123)) 
 
       return true; 
 
      else 
 
       return false; 
 
     } 
 
     catch (err) { 
 
      alert(err.Description); 
 
     } 
 
    }
@Html.EditorFor(model => model.FirstName, new { @class = "form-control", @placeholder = "First Name", @id = "txtFirstName", @maxlength = "50", onkeypress = "return onlyAlphabets(event,this);" }) 
 
@Html.EditorFor(model => model.LastName, new { @class = "form-control", @placeholder = "Last Name", @id = "txtLastName", @maxlength = "50", onkeypress = "return onlyAlphabets(event,this);" })