我可以在 javascript 或 jquery 中模拟按键(CTRL+F1)吗?

Vic*_*888 6 html javascript jquery

您好,当我单击按钮时,想模拟按下 CTRL+F1 键。例如:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.js">
        function simulateKeyPress(){

        }
    </script>

    <button class="boton3d" onclick="simulateKeyPress()"> 
           <img src="img/phone.png">       
    </button> 
Run Code Online (Sandbox Code Playgroud)

谢谢...

Mil*_*war 3

你可以试试:

  var e = jQuery.Event("keydown");
  e.which = 112;       // # F1 code value
  e.ctrlkey = true;     // control key pressed
  $(document).trigger(e);// trigger event on document
Run Code Online (Sandbox Code Playgroud)