Key press 'enter' on web page does not work on chrome

时间:2016-02-27 22:07:42

标签: javascript jquery google-chrome

I have javascript that handling key press enter trigger specific button event:

if (window.event)
    key = window.event.keyCode;     //IE
else
    key = e.which;     //firefox

if (key == 13) {
//Get the button the user wants to have clicked
var btn = document.getElementById(buttonName);
if (btn != null) { //If we find the button click it
    btn.click();
    event.keyCode = 0
}

It's works on IE and Firefox, but not on Chrome. Any solutions?

1 个答案:

答案 0 :(得分:0)

@Override public List<Localidades> verLocalidades() { List<Localidades> listaLocalidades = null; Session sesion = HibernateUtil.getSessionFactory().openSession(); Transaction transaccion = sesion.beginTransaction(); String hql = "FROM Localidades"; //String hql = "SELECT l.idlocalidad, l.descripcion, l.esrural, l.iddistrito, l1.Descripcion FROM localidades l LEFT OUTER JOIN localidades l1 ON l.`idlocalidadpadre` = l1.`idlocalidad`"; try { listaLocalidades = sesion.createQuery(hql).list(); transaccion.commit(); //sesion.close(); } catch (Exception e) { transaccion.rollback(); }finally{ if(sesion != null){ //sesion.close(); } } return listaLocalidades; } 用于Chrome。据我所知,它也适用于IE和Firefox