【问题标题】:press enter key with a click?点击回车键?
【发布时间】:2017-11-11 15:15:35
【问题描述】:

我有一个特殊的鼠标,它通过按钮进行控制。我的意思是,当我按下左键焦点前进时,当我按下中间焦点时,右键按下。它在某些带有右键的对象中效果不佳,因为某些网站无法识别单击,所以我想用输入键更改 clck,我的意思是当我按下右键时,我想要一个键输入推。我不知道我是否很清楚。这是实际代码:

$(":focusable").eq(0).focus();
var currentFocus=$(":focusable").eq(0);


$(document).ready(function(){
    $("#prueba1").mousedown(function(e){
    //1: izquierda, 2: medio/ruleta, 3: derecho         
    if(e.which == 3)                {
    //PlaySound3("http://www.soundjay.com/button/beep-06.wav");
    //PlaySound3("https://www.soundjay.com/button/button-30.wav");
    PlaySound4();
       if(currentFocus!=undefined){
        currentFocus.focus();
        currentFocus.trigger('click');

        if(currentFocus.prop('tagName')=='A'){
             window.location.href = currentFocus.attr('href');
        };
    }
    return false;           
    }
    if(e.which == 2)                {
    PlaySound3();
    var focusables= $(":focusable");
    var current= focusables.index(currentFocus);
    var previous = focusables.eq(current-1).length ? focusables.eq(current-1) : focusables.eq(0);
    currentFocus=previous;
    previous.focus();
    return false; 
    }
    if(e.which == 1)                {
        parar();
        PlaySound();
        //PlaySound3("http://www.soundjay.com/button/beep-07.wav");
    var focusables= $(":focusable");
    var current= focusables.index(currentFocus);
    var next = focusables.eq(current+1).length ? focusables.eq(current+1) : focusables.eq(0);
    currentFocus=next;
    next.focus();
    return false;    
    }
    });
    }); 

非常感谢你!

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    像这样在右键单击时触发回车键。

    var e = $.Event( "keypress", { which: 13 } );
    $('#yourInput').trigger(e);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-22
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 2020-08-21
      • 2019-05-28
      • 2019-10-06
      • 2013-01-25
      相关资源
      最近更新 更多