Trigger Keypress with jQuery

后端 未结 2 1246
情歌与酒
情歌与酒 2020-11-29 10:44

On the Definitive Trigger Keypress jQuery thread there is no working JSFiddle for the answer, and the code that is there doesn\'t work for me.

$(\"button\")         


        
相关标签:
2条回答
  • 2020-11-29 11:23

    SublimeVideo is a HTML5 player, correct. If so, you can mute it by using a property, right?

    $("video#yourVideoTagId").prop("muted", true);
    
    0 讨论(0)
  • 2020-11-29 11:25

    Using trigger you are just triggering the event with a keycode but not assigning the value to the textbox. Try this :- http://jsfiddle.net/PbHD2/

    String.fromCharCode

    $("button").click(function() {
         $("input").focus();
        var e = jQuery.Event("keydown");
        e.which = 77; // # Some key code value
        $("input").val(String.fromCharCode(e.which));
        $("input").trigger(e);
    });
    $('input').keydown(function(e){
       console.log('Yes keydown triggered. ' + e.which)
    });
    
    0 讨论(0)
提交回复
热议问题