简体   繁体   English

ColdFusion Javascript验证

[英]ColdFusion Javascript Validation

Is it possible to write JavaScript Validation for ColdFusion Inputs and Selects? 是否可以为ColdFusion输入和选择编写JavaScript验证?

My desired Outcome 我想要的结果
(I have this piece that works perfect with Inputs but I have ColdFusion select statements (that are includes) and this script for validation just skips over them.. Is there anyway to call out ColdFusion Inputs and Selects making them required and not required depending on a Yes/No radio button?) (我有一块可以完美地与Inputs配合使用,但我有ColdFusion select语句(包含在内),并且此验证脚本只是跳过了它们。是否总有需要调出ColdFusion Inputs和Selects来使它们成为必需项,而不取决于它们是/否单选按钮?)

http://jsfiddle.net/0kaxb6qt/ http://jsfiddle.net/0kaxb6qt/

$('#div1 input').each(function() {
   $(this).removeAttr('required'); 
});

function showhideForm(Mailto_1) {
        if (Mailto_1 == "Yes") {
            document.getElementById("div1").style.display = 'block';
            document.getElementById("div2").style.display = 'none';
            $('#div1 input').not('#cmiddlename_1').not('#cm2street_1').each(function() {
                //console.log('wat');
                $(this).attr('required', 'required');
            });
        } else if (Mailto_1 == "No") {
            document.getElementById("div2").style.display = 'block';
            document.getElementById("div1").style.display = 'none';
            $('#div1 input').each(function() {
                $(this).removeAttr('required');
            });
            $("#div1 > .clearfix input:text").val("");
        }
    }

You can grab the id and set required to either true or false: 您可以获取ID并将其设置为true或false:

$('#cmiddlename_1').prop('required',true);
$('#cm2street_1').prop('required',false);

Basically turning them off and on. 基本上将它们关闭然后再打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM