Javascript capture key

前端 未结 3 1945
情深已故
情深已故 2020-12-03 19:31

I am trying to catpure the enter key from a textarea using javascript. The problem is that although I am able to find out that the \"enter\" key was pressed, I am not unable

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 20:11

    Try setting this function as the onKeyDown event for the text area:

    ex: onkeydown="javascript:return fnIgnoreEnter(event);"

    function fnIgnoreEnter(thisEvent) {
      if (thisEvent.keyCode == 13) { // enter key
        return false; // do nothing
      }
    }
    

提交回复
热议问题