javascript - 如何检测一个按钮是否在jquery中被折叠?
问题描述
我有以下按钮:
<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 有一个方法可以做到这一点:
从文档:
描述:将处理程序附加到元素的事件。每个事件类型的每个元素最多执行一次处理程序。
在你的情况下:
$('.js-user-btn').one('click', function() {...
推荐阅读
- node.js - Node JS - 如何等到Google Cloud Storage Bucket上存在文件,然后下载文件
- css - Bootstrap 4 - 如何正确居中 Div(表单)?
- python - pandas Series.map() 的内部实现是什么?
- go - 为什么要自动构建/安装更新所需的软件包?
- mysql - 比较大文本字段是否相等
- azure - “az ad app permission add ...”的 terraform 等价物是什么?
- azure - 我需要从 C# 将日志附加到 DataLake Gen 2 的 blob 存储中的 Auditlog.csv 文件
- java - 在二维数组中查找邻居(不包括对角线)
- sidekiq - 同时启动sidekiq pro 5的rails服务器错误
- react-native - 可以`npm安装
` 文件夹与 react native 一起使用?