gpt4 book ai didi

javascript - 获取被激发(触发)的事件的名称(类型)

转载 作者:IT王子 更新时间:2023-10-29 03:06:59 25 4
gpt4 key购买 nike

我有以下代码:

$('#button').on('click change', function() {
alert('Who fired me, click or change?');
});

我如何知道调用的事件是“点击”还是“更改”?

最佳答案

event.type 会得到你想要的。

DEMO

另见: List of event types

$('#button').on('click change', function(){
console.log(event.type + ' is fired');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<input type="text" id="tipo-imovel" />

关于javascript - 获取被激发(触发)的事件的名称(类型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9724944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com