为什么我得到的getElementyById不是函数?
window.getElementById('notes').addEventListener('keydown', function (e) { // Allow: backspace, delete, tab, escape, enter and . if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || // Allow: Ctrl+A (e.keyCode == 188 && e.shiftKey === true) || // Allow: Ctrl+A (e.keyCode == 190 && e.shiftKey === true) || // Allow: Ctrl+A (e.keyCode == 191 && e.shiftKey === true) || // Allow: Ctrl+A (e.keyCode == 65 && e.ctrlKey === true) || // Allow: Ctrl+C (e.keyCode == 67 && e.ctrlKey === true) || // Allow: Ctrl+X (e.keyCode == 88 && e.ctrlKey === true) || // Allow: home, end, left, right (e.keyCode >= 35 && e.keyCode <= 39)) { // let it happen, don't do anything return; } // Ensure that it is a number or alphabet and stop the keypress if ((e.altKey) || e.keyCode == 191 || (e.keyCode < 48 || e.keyCode > 90) && (e.keyCode < 96 || e.keyCode > 105)) { e.preventDefault(); } }, false);
michaelitoh.. 5
添加侦听器的正确对象document
不是windows
。
有了这样说尝试:
document.getElementById("elementId")
添加侦听器的正确对象document
不是windows
。
有了这样说尝试:
document.getElementById("elementId")