尽管已经设置了一些JS代码,但我的复选框上的[[属性为什么不起作用?

问题描述 投票:0回答:2
[对,为什么仍然有可能发送我创建的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>
<label class="no-content" style="display: inline;">
  <input name="agreePP" id="myCheck" type="checkbox" value="agreePP" required>
  <span class="label-text">I accept and agree to the Privacy Policy*</span>
  <p id="demo" class="label-text" style="color:red!important;"></p>
</label>
<input onClick="consentValidation()" class="std_button" type="submit" value="Submit"/>
此外,为什么删除checked属性时,复选框的默认状态为选中状态,反之亦然。当我插入checked属性时,默认状态保持未选中状态吗?

这也是自定义CSS checkbox,因此为什么挖矿要比大多数挖矿复杂一些。抱歉,这是我们对隐私政策的同意,因此出于明显原因,必须100%正确。

说实话,这简直不是开玩笑,但是如果有人可以对此有所了解,那就太好了。

谢谢

javascript html css
2个回答
1
投票
很简单。您应该将它们包装在表单元素中:

<form> ... </form>

以及您可能需要的其他属性,例如操作,方法。检查docs

0
投票
您需要将输入内容包装成表格才能正常工作。这是您的更新代码

<form> <label class="no-content" style="display: inline;"> <input name="agreePP" id="myCheck" type="checkbox" value="agreePP" required> <span class="label-text">I accept and agree to the Privacy Policy*</span> <p id="demo" class="label-text" style="color:red!important;"></p> </label> <input onClick="consentValidation()" class="std_button" type="submit" value="Submit"/> </form>

© www.soinside.com 2019 - 2024. All rights reserved.