preventDefault()不适用于Firefox 9.0.1中的SELECT元素 [英] preventDefault() not working on SELECT elements in Firefox 9.0.1

查看:130
本文介绍了preventDefault()不适用于Firefox 9.0.1中的SELECT元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到有一些有关preventDefault()的Firefox还没有使用的其他问题,但是他们没有帮助我。

I realise there are other questions on preventDefault() not working with Firefox, but they did not help me.

我有三个SELECT列表,所有我想要使​​用箭头键在它们之间导航,而不改变任何值。该代码在Chrome中运行良好,但在Firefox中,它会移动焦点,然后更改刚刚移动到的元素上的值。

I've got three SELECT lists, and all I want is to navigate between them using the arrow keys without changing any values. The code works great in Chrome, but in Firefox it moves focus and then changes the value on the element just moved to.

http://jsbin.com/ofitif/3/edit

JavaScript:

$(document).ready(function () { 
  $('.myinput').keydown(function (evt) { onkeydown(evt); });
  $('.myinput:first').focus(); 
}); 

function onkeydown(evt) {
  evt.preventDefault();
  console.log(evt.which);
  if(evt.which == 39) {
    $(document.activeElement).next().focus();
  }
  else if(evt.which == 37) {
    $(document.activeElement).prev().focus();
  }             
}

HTML: p>

HTML:

<div id="inputs">
    <select class="myinput">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
    </select>
    <select class="myinput">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
    </select>
    <select class="myinput">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
    </select>
</div>


推荐答案

根据您的要求,尝试传递值以防止默认。 .it将像下面这样。

according to your requirement try passing value for prevent default..it will be something like below..

evt.preventDefault ? evt.preventDefault() : evt.returnValue = false;

它适用于我plz尝试.......

it worked for me plz try it.......

这篇关于preventDefault()不适用于Firefox 9.0.1中的SELECT元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆