javascript - 为什么不是尽管设置了一些 JS 代码,但我的复选框上的属性仍然有效?
问题描述
是的,为什么仍然可以发送html
我创建的表单而无需检查隐私政策同意checkbox
,尽管 JS 代码要求用户checkbox
需要检查要提交的表单?
我的浏览器是 Edge。
继承人的代码:
#agreeCheckbox{
position: absolute;
display: inline;
margin-left: 5px;
margin-bottom: 12000px;
padding:5px;
background-color: white;
}
#agreeCheckbox {
display: none;
margin-bottom: 20px;
}
input + .label-text:before{
content:"\f046 ";
font-family: Fontawesome;
margin-right: 5px;
display: inline-block;
width: 1em;
font-size: 15px;
line-height: 1;
font-weight: normal;
font-style: normal;
font-variant: normal;
}
input:checked + .label-text:before{
content: "\f096 ";
font-family: Fontawesome;
line-height: 1;
font-weight: normal;
font-style: normal;
font-variant: normal;
font-size: 15px;
}
.label-text{
font-size: 15px;
color: #FFF;
font-weight: normal!important;
cursor: pointer!important;
}
.no-content:after{
content: "";
margin-top:5px;
}
<script>
function consentValidation() {
var x = document.getElementById("myCheck").required;
document.getElementById("demo").innerHTML = "You must consent to our Privacy Policy before submitting this form.";
}
</script>
<form method="post" action="../php/services-interest-form.php" enctype="multipart/form-data">
<p class="legal-section-title" style="color: #FFF!important;">Privacy Notice</p>
<p style="color: #FFF!important;">We want you to know how our service works and why we need your registration details. Please read our <a href="../pages/privacy policy.html">Privacy Policy</a> and then tick below that you agree with it.</p><br/>
<label class="no-content" style="display: inline;">
<input name="agreePP" id="myCheck" type="checkbox" value="true" required />
<span class="label-text">I accept and agree to the Privacy Policy*</span>
<p id="demo" class="label-text" style="color:red!important;">You must consent to our Privacy Policy before submitting this form.</p>
</label>
</div><br/>
<input onClick="consentValidation()" class="std_button" type="submit" value="Submit"/>
</form>
除此之外,为什么当我删除checked
属性时,复选框的默认状态是选中状态,反之亦然。当我插入checked
属性时,默认状态保持未选中?
这也是一个自定义 css checkbox
,因此为什么挖矿比大多数复杂一点。对此感到抱歉,但这是对我们隐私政策的同意,因此出于显而易见的原因,这需要 100% 正确。
老实说,这已经超出了一个笑话,但如果有人能对此有所了解,那就太好了。
谢谢
解决方案
推荐阅读
- sql - Postgesql:加入或子查询问题
- node.js - 在 Docker 中构建 Angular 会引发“文件替换中的 environment.prod.ts 路径不存在”
- laravel - 在应用程序\用户 laravel 7 中找不到方法“创建”
- c - 为什么第二条语句创建分配给非左值''main.c?
- c - 在 C 中的链表中的特定位置插入节点(仅限)
- android - 如何在 Android 应用程序中使用 C++ buider 写入文件?
- r - 具有连续变量和分类变量的逻辑回归模型
- jquery - 根据日期以升序或降序反转表 td
- java - 为什么以下两种方法之间存在性能差异?
- jenkins - Jenkins管道:动态并行执行步骤