gpt4 book ai didi

javascript - 限制用户只能点击标签一次

转载 作者:行者123 更新时间:2023-12-03 11:16:20 24 4
gpt4 key购买 nike

我遇到了有关 anchor 标记同时多次点击的问题。我有页面 abc.html它有一个 anchor 标签。当用户单击该链接时,它会处理一个订单请求。现在,如果用户多次单击该链接,我将面临什么问题,然后我会收到重复的订单。所以我决定限制 anchor 标记只能单击一次。我做了一些研发,我发现了一个代码,但第一次单击时它是禁用链接,而我想在第二次单击时禁用它。代码如下

<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
a.disabled:link, a.disabled:visited { color: grey; }
</style>
<script>
$(#document).ready(function(){
$("#disabled a").click(function () {
$(this).fadeTo("fast", .5).removeAttr("href");
});
});
</script>
</head>
<body>
<a href="http://google.com" onclick="this.removeAttribute('href');this.className='disabled'">Link</a>
</body>
</html>

最佳答案

您可以使用一个:

$("#disabled a").one('click',function () {
//to do here
});

示例:

$(function() {
$('#link').one('click', function() {
console.log('in here ...');
$(this).removeAttr('href');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a target="_blank" href="http://www.w3schools.com" id='link'>W3 Schools</a>

关于javascript - 限制用户只能点击标签一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27329784/

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