Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 鼠标点击和按键功能相同_Javascript_Jquery_Html - Fatal编程技术网

Javascript 鼠标点击和按键功能相同

Javascript 鼠标点击和按键功能相同,javascript,jquery,html,Javascript,Jquery,Html,我想在鼠标单击或按键时调用jquery中的函数 一种方法是为这两个事件编写两次相同的代码,但这不是正确的方法 有谁能告诉我这是怎么可能的吗?只编写一个函数,并在两个事件上调用它 $( "#target" ).keypress(function() { funABC; }; funABC; }; 还有一条捷径: $( "#target" ).click(function() { $( "#target" ).keypress(); }); $( "#target" ).ke

我想在鼠标单击或按键时调用jquery中的函数

一种方法是为这两个事件编写两次相同的代码,但这不是正确的方法


有谁能告诉我这是怎么可能的吗?

只编写一个函数,并在两个事件上调用它

$( "#target" ).keypress(function() {
funABC; };

funABC; };

还有一条捷径:

    $( "#target" ).click(function() {
  $( "#target" ).keypress();
});


   $( "#target" ).keypress(function() {
funABC();
});

如果要将两个处理程序注册到同一元素,则可以使用为多个事件注册处理程序

$('myelementselector').on('click keypress', function () {
    //mycode
})
使用on方法

是的,你可以用like

<input type="text"  />


$(document).on("click mouseenter","input",function(){});
试试这个:-

$element.在“单击按键”上,按“向下键”功能{

})

编写一个函数

function Process(){
//Put all your logic
}

call the function in all the event 

$("some element selector").on("click keypress",function() {
     Process();
});
或任何其他单击事件。

您还可以使用:

$( "input" ).on('keypress mouseup',function() {

 alert('done');

});


您可以创建一个函数并为两个事件注册它。您可以创建一个jquery函数并为两个jquery事件注册它。是否可以在jquery中执行此操作?element.clickfunction{}$document.onkeypress mouseenter,输入,函数{}@Kasma mouseenter不是点击事件是的,他可以使用mousedown或click,这只是将两个事件组合成一个mouseenter的例子,而不是点击事件
<input type="text"  />


$(document).on("click mouseenter","input",function(){});
function Process(){
//Put all your logic
}

call the function in all the event 

$("some element selector").on("click keypress",function() {
     Process();
});
$( "input" ).on('keypress mouseup',function() {

 alert('done');

});
$( "input" ).on('keypress mouseup',fun);