Prevent backspace from navigating back in AngularJS

后端 未结 4 1579
Happy的楠姐
Happy的楠姐 2021-01-12 12:03

I faced this issue in my AngularJS webapp.

When a user enters a page with a form to fill and he starts typing, if he presses the backspace key and the focus is not o

4条回答
  •  灰色年华
    2021-01-12 13:02

    I can't comment "accepted answer", but it will work not right, as condition

    e.which === 8 && e.target.nodeName !== "INPUT" || e.target.nodeName !== "SELECT"
    

    with logic error, so you can use

    e.which === 8 && e.target.nodeName !== "INPUT" && e.target.nodeName !== "SELECT"
    

    or answer that wrote @ThisIsMarkSantiago.

提交回复
热议问题