gpt4 book ai didi

javascript - jquery中如何检测按钮是否折叠?

转载 作者:行者123 更新时间:2023-12-02 23:03:44 24 4
gpt4 key购买 nike

我有以下按钮:

 <button class="mdl-button mdl-js-button mdl-button--icon js-user-btn is-collapsed" data-quoteid="@user.UserId">
<i class="icon-chevron-right"></i>
</button>

我在该按钮上有一个点击事件:

  $('.js-user-btn').click(function() {

$.ajax({
type: "POST",
url: "@(Url.Action("GetUserDetails", "User"))",
data: {
"user": id,
"language": "en-GB"
},
success: function (data) { // I want to trigger the an ajax function here, on the first click of the button.

On the second the click of the button, the ajax should not be triggered. }

我想在第一次单击按钮时触发 ajax 函数。

第二次单击按钮时,不应触发 ajax。

最佳答案

jQuery 有一个方法可以解决这个问题:

https://api.jquery.com/one/

来自文档:

Description: Attach a handler to an event for the elements. The handler is executed at most once per element per event type.

就您而言:

$('.js-user-btn').one('click', function() {...

关于javascript - jquery中如何检测按钮是否折叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57686100/

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