gpt4 book ai didi

javascript - jquery如何获取点击了哪个链接

转载 作者:太空宇宙 更新时间:2023-11-03 19:58:48 26 4
gpt4 key购买 nike

美好的一天...

我有多个链接如下:

<li><a href="#" id="mmSaveForm" class="itemDisabled noTxtSelect1">Save</a></li>
<li><a href="#" id="mmSaveAs" class="itemDisabled noTxtSelect1">Save As</a></li>
<li><a href="#" id="mmSaveExit" class="itemDisabled noTxtSelect1">Save And Exit</a></li>

我想知道哪个链接被点击了我试过这样的事情:

if ($("#mmSaveForm").click() == "true") {
//do something
}
else if ($("mmSaveAs").click() == "true") {
//Do something
}
else if ($("#mmSaveExit").click() == "true") {
//Do something
}

我尝试了这些链接、问题和答案,但它们没有帮助:

How can I get the button that caused the submit from the form submit event?

jQuery: how to get which button was clicked upon form submission?

how to detect which button is clicked using jQuery

jQuery - how to determine which link was clicked

我整晚都在尝试这个,请帮忙...提前谢谢你...

最佳答案

为什么不以类为目标,获取 id 然后使用 switch 语句。

$('.itemDisabled').on('click', function () {
var id = this.id;
switch(id) {
case 'mmSaveForm':
// code
break;
case 'mmSaveAs':
// code
break;
case 'mmSaveExit':
// code
break;
}
});

关于javascript - jquery如何获取点击了哪个链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24930080/

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