JS按两次回车触发事件 想做一个功能就是按一次回车是普通换行,在空行再按回车触发事件,代码如下: <textarea name="text" onkeydown="check(this);">测试文本</textarea> <script> function check(that){ if(window.event.key=='Enter'){ if(['\r','\n'].indexOf(that.value.substring(that.selectionStart-1,that.selectionStart))>=0 || ['\r','\n'].indexOf(that.value.substring(that.selectionEnd,that.selectionEnd+1))>=0){ window.event.stopPropagation(); window.event.preventDefault(); alert('Hi'); }; }; }; </script>