【发布时间】:2017-05-20 03:06:52
【问题描述】:
在我的代码中,我有twobuttons,我想确认如果用户点击其中任何一个,它将执行function(它已经工作),但如果它再次点击, 它不会做任何事情。
我的 HTML 代码:
<html>
<head>
<meta charset="UTF-8">
<title>Demo</title>
<script src="jquery-3.1.1.js"></script>
<script src="JS.js"></script>
<!--script src="JS2.js"></script-->
</head>
<body>
<p><input type="button" name="click" value="Button I" id="1" onclick="myFunction();"/></p>
<p><input type="button" name="click" value="Button II" id="2" onclick="myFunction2();"/></p>
</body>
</html>
我的函数代码(.js):
function myFunction(xx, xx, numberOrigin){
numberOrigin +=1;
$.ajax({
type: 'POST',
dataType: "json",
contentType: "application/json",
url: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
data: JSON.stringify({
"xxxxxxxxxxx":xxxxxxx,
"xxxxxxxxxxxx":xxxxxxxxx,
"xxxxxxxxxxxx":"xxxxxxx"
}),
success:function(output) {
console.log(output);
otherFunction(xxxxxxxxxxxxxxxx, numberOrigin);
},
error:function(output) {
}
});
}
提前感谢。
【问题讨论】:
-
点击后为什么不禁用呢?
-
您使用什么变量来存储按钮点击次数?您在哪里测试这是第一次点击其中一个按钮?
-
disable它在函数的末尾 -
这种情况下,只有点击后禁用。我将在数据库中创建一个表来检查@Cubi,但我会在之后尝试。这只是一个测试
标签: javascript jquery html