2013-07-03 49 views
0

在我的應用程序中,我有一個文本區域,用戶無法刪除使用退格鍵輸入的字符或在IE9中使用刪除鍵。這適用於Chrome。退格和刪除按鈕不會刪除IE上的textarea中的字符

我有以下代碼

$('textarea').live('keydown', function(e) { 
     var keyCode = e.keyCode || e.which; 
     if (keyCode == 9) { 
      var currentIndex = getCaret($(this).get(0)) 
      selectText($(this), currentIndex); 
      return false; 
     } 
    }); 
}); 

和使用IM的jQuery.highlighttextarea.js其中突出的圖案的話。 我不確定是否需要修改jQuery.highlighttextarea.js以處理退格或刪除。 請建議

我沒有使用它像

我沒有使用它像

if (e.which == 9) { 
var currentIndex = getCaret($(this).get(0)) 
      selectText($(this), currentIndex); 
      return false; 
    } 

if (e.which == 8 || e.which == 46) { 
    return false; 

} 

但是現在退格或刪除不工作

+2

不要使用'VAR鍵代碼= e.keyCode || e.which;'。 jQuery將關鍵代碼標準化爲'e.which' - 只是使用那個 – Ian

+6

...並且'live'已經死了。 – undefined

+1

@undefined大聲笑,很好的 –

回答

1

這觸發加入jquery.highlighttextarea.js

'keydown.highlightTextarea' : $.proxy(function(e) { 

        var keyCode = e.keyCode || e.which; 
        if (keyCode == 9) { 
         var currentIndex = getCaret($(e.target).get(0)) 
         selectText($(e.target), currentIndex); 
         return false 
        } 
        if (keyCode == 8 || keyCode == 46) { 
         this.highlight(true); 
        } 
        this.highlight(true); 

       }, this),