jquery - 需要启用按钮 WHEN Recaptcha 和复选框已被验证
问题描述
我对 Django 和 jQuery 很陌生,所以在这里需要一些帮助(基本上是菜鸟)。从服务器端验证验证码后,我需要启用开始测试按钮,不能从前端绕过并且复选框已被选中。我之前做过复选框,但不知道如何添加验证码。
代码
<div
class="g-recaptcha captcha-button"
align="center"
data-sitekey="sitekey"
></div>
<br />
<div class="form-check test-check-button" align="center">
<input type="checkbox" class="form-check-input display-7" id="instructions" />
<label class="form-check-label text-center" for="instructions">
<strong>I have read the instructions given above.</strong></label
>
</div>
<div class="mb-5 mt-2 text-center start-button" id="startButton"></div>
<script>
$("#instructions").on("click", function () {
$.ajax({
type: "GET",
url: "/test/confirm",
data: {
checkbox: 1,
},
dataType: "json",
success: function (data) {
if (data.button) {
$(".test-check-button").html("");
$(".start-button").html(data.button);
}
},
});
});
</script>
视图.py
def confirm(cls, request: HttpRequest):
button = '<button class="btn btn-primary mt-3" id="submit_test" type="submit">Start
Test</button>'
data = {'button': button}
return JsonResponse(data)
项目中没有forms.py。所以想知道如何在没有表单的情况下验证验证码服务器端并在验证和复选框被选中后启用“开始测试”按钮。谢谢你。
解决方案
有一个数据回调属性:
function myCallback(){
$('button').prop( "disabled", false )
}
<div class="g-recaptcha" data-callback="myCallback"/>
推荐阅读
- node.js - 如何获得使用 Express.js/Nodemon 的持久会话?
- javascript - 根据输入的焦点显示元素
- python - anaconda环境位置问题
- laravel - 如果低优先级作业需要很长时间才能完成,工匠队列中的低优先级作业会停止执行高优先级任务吗?
- java - 如何将.dex文件转换为android studio项目
- x86-16 - 如何打印存储在变量中的整数
- python - 混合龙卷风和 sqlalchemy
- java - 在java中使用opencv录制和保存视频流
- r - ggplot构面图重新排序未按预期工作
- algorithm - 我正在努力为我的家庭作业找到有效的解决方案。冒泡排序还是插入排序?