[英]How do I validate radio buttons using formvalidation.io and jQuery?
[英]How do I validate Radio Buttons for the Unbounce Platform using Jquery?
我正在尝试为着陆页设置联系表格,其中潜在客户必须单击“是”才能阅读服务条款。 与“是”和“否”单选按钮相比,简单地拥有一个“我接受”复选框会容易得多,但不幸的是,这就是对我的要求。 我使用 Unbounce 作为平台。 有人可以帮我写出代码吗? 谢谢 :)
lp.jQuery(function($) {
// Config
var ruleID = 'I have read the TOS';
var field = 'terms_of_service';
var message = 'Please confirm you have read the Terms of Service by clicking YES';
var rules = module.lp.form.data.validationRules[field];
...
这是检查单选按钮或复选框是否被选中的代码。 请记住,您必须将checked
HTML 属性添加到“否”,以便默认情况下选中它。
function check() { if ($("#yesb").prop("checked")) { console.log("Accepted!"); } else { console.log("Not accepted. :-("); } }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <label><input name=accepted type=radio id=yesb>Yes</label> <label><input name=accepted type=radio id=nob checked>No</label> <button onclick=check()>Check</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.