如何在所有字段为true后激活注册按钮
How to activate registration button after all fields are true
这是我检查字段是真还是假的情况
function textoEnP(){
var idInput2 = $(this).attr("id");
switch(idInput2){
case "nombre":
{
if($(this).val() == ""){
$(".texto_req_reg").html("No puede estar vacio");
$(".texto_req_reg").css("color", "#C60");
nombreValido = false;
}else{
$(".texto_req_reg").html("Correcto");
$(".texto_req_reg").css("color", "#990");
nombreValido = true;
}
break;
}
case "apellido":
{
if($(this).val() == ""){
$(".texto_req_reg").html("No puede estar vacio");
$(".texto_req_reg").css("color", "#C60");
apellidoValido = false;
}else{
$(".texto_req_reg").html("Correcto");
$(".texto_req_reg").css("color", "#990");
apellidoValido = true;
}
break;
}
case "edad":
{
if(isNaN($(this).val())){
$(".texto_req_reg").html("Debe ingresar solo numeros");
$(".texto_req_reg").css("color", "#C60");
edadValida = false;
}else if($(this).val() == ""){
$(".texto_req_reg").html("No puede estar vacio");
$(".texto_req_reg").css("color", "#C60");
edadValida = false;
}else{
$(".texto_req_reg").html("Correcto");
$(".texto_req_reg").css("color", "#990");
edadValida = true;
}
break;
}
case "mail":
{
if($(this).val().length < 9 && isNaN($(this).val())){
$(".texto_req_reg").html("Debe usar un formato valido");
$(".texto_req_reg").css("color", "#C60");
mailValido = false;
}else if($(this).val() == ""){
$(".texto_req_reg").html("No puede estar vacio");
$(".texto_req_reg").css("color", "#C60");
mailValido = false;
}else{
$(".texto_req_reg").html("Correcto");
$(".texto_req_reg").css("color", "#990");
mailValido = true;
}
break;
}
case "contraseña":
{
password = $(this).val();
if($(this).val().length < 9){
$(".texto_req_reg").html("Debe tener más de 8 caracteres");
$(".texto_req_reg").css("color", "#C60");
}else{
$(".texto_req_reg").html("Correcto");
$(".texto_req_reg").css("color", "#990");
contraseñaValida = true;
}
break;
}
case "repetir_contraseña":
{
if($(this).val() !== password){
$(".texto_req_reg").html("Debe coincidir con su contraseña");
$(".texto_req_reg").css("color", "#C60");
}else{
$(".texto_req_reg").html("Correcto");
$(".texto_req_reg").css("color", "#990");
repContraseñaValida = true;
}
break;
}
if($("#checkbox_legales").is(":checked")){
checkbox_legalesValido = true;
}else{
checkbox_legalesValido = false;
}
habilitarBoton();
}
}
如果一切正常,这是激活注册按钮的功能
function habilitarBoton(){
if(nombreValido && apellidoValido && edadValido && mailValido && contraseñaValida && repContraseñaValida && checkbox_legalesValido)
{
$("#registrarse").removeAttr("disabled").css('background-color', '#fff');;
}else{
$("#registrarse").attr("disabled", "disabled").css({'background-color' : '#ccc', 'color' : '#000'});
}
}
主要的问题是复选框的条件,不起作用不知道为什么,在我弄清楚之前,我的表单不会起作用。有什么建议吗?
编辑:这是HTML
<div id="cuadro_izq">
<form>
<div class="titulo_loguearse">
LOGUEARSE
</div>
<div id="form_loguearse">
<div class="renglon">
<label for="tex1" class="loguin_label">Mail:</label>
<INPUT type="text" NAME="mail" id="tex1" class="loguin_field"><br />
</div>
<div class="renglon">
<label for="tex2" class="loguin_label">Contraseña:</label>
<INPUT TYPE="password" NAME="contrasena" id="tex2" class="loguin_field">
</div>
</div>
<div id="boton_loguin">
<input type="submit" value="Entrar" id="entrar" />
</div>
</form>
</div>
<div id="cuadro_der">
<form>
<div class="titulo_loguearse">
REGISTRARSE
</div>
<div id="form_registro">
<div class="renglon">
<label for="tex3" class="loguin_label">Nombre:</label>
<INPUT type="text" NAME="nombre" id="nombre" class="registro_field"><br />
<div id="caja_req_reg_nom">
</div>
</div>
<div class="renglon">
<label for="tex4" class="loguin_label">Apellido:</label>
<INPUT TYPE="text" NAME="apellido" id="apellido" class="registro_field"><br />
<div id="caja_req_reg_ape">
</div>
</div>
<div class="renglon">
<label for="tex5" class="loguin_label">Edad:</label>
<INPUT type="text" NAME="edad" id="edad" class="registro_field"><br />
<div id="caja_req_reg_edad">
</div>
</div>
<div class="renglon">
<label for="tex6" class="loguin_label">Mail:</label>
<INPUT TYPE="text" NAME="mail" id="mail" class="registro_field"><br />
<div id="caja_req_reg_mail">
</div>
</div>
<div class="renglon">
<label for="tex7" class="loguin_label">Contraseña:</label>
<INPUT type="password" NAME="contraseña" id="contraseña" class="registro_field"><br />
<div id="caja_req_reg_pass">
</div>
</div>
<div class="renglon">
<label for="tex8" class="loguin_label">Repetir contraseña:</label>
<INPUT TYPE="password" NAME="repetir_contraseña" id="repetir_contraseña" class="registro_field"><br />
<div id="caja_req_reg_repass">
<!--<p class="texto_req_reg">Texto prueba</p>-->
</div>
</div>
<div class="renglon" id="renglon_legales">
<INPUT TYPE="checkbox" NAME="aceptar_legal" id="checkbox_legales">
<label for="tex9" id="legales_label">Acepto las disposiciones legales</label><br />
</div>
</div>
<div id="boton_registrarse">
<input type="submit" value="Registrarse" id="registrarse" disabled="disabled" />
</div>
</form>
</div>
尝试
if($("#checkbox_legales").prop(":checked"))
更多信息
http://christierney.com/2011/05/06/understanding-jquery-1-6s-dom-attribute-and-properties/
idInput2
仅匹配1个CCD_ 1,因此未达到所有其他条件。因此,如果您调用该函数一次,则只有一个验证为true,如果您为每次验证都调用它,则您可能希望将对habilitarBoton()
的调用从该函数
相关文章:
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- AngularJS-使用'true'属性
- 激活chrome上的chrome.notifications对象
- 提示使用服务器端事件处理程序激活JavaScript
- 如何从外部页面激活非默认引导选项卡
- 选项卡侦听器未被来自后台脚本的消息激活
- JavaScript-切换“;全部检查”;复选框true/false
- location.reload(true)崩溃浏览器选项卡
- 基于localStorage的Meteor激活模板
- 指令的模板必须只有一个根元素:With restrict E&替换true
- JavaScript:只有当数组中的所有项都为true时才执行函数
- 对于loop.if-仅在经过所有间隔后返回true
- if(foo!==null)的计算结果为true,即使foo为null
- 如何通过按键激活按钮应用CSS效果
- ngIf的计算结果始终为true
- 在BoilerplateJS浏览器加载所有脚本(在其他模块中),而不考虑激活的模块
- 我必须点击两次才能激活任何按钮操作(离子/角度)
- 如果函数返回True,则显示Javascript按钮
- (false==false==true)怎么可能是真的
- 如何在所有字段为true后激活注册按钮