gpt4 book ai didi

javascript - $(input).blur() & $(input).focusout

转载 作者:行者123 更新时间:2023-11-28 07:30:35 29 4
gpt4 key购买 nike

我有下一个 html 表单:

<form role="form" action="MAILTO:alejandro@distal.com.ar " method="post" enctype="text/plain" id="form-contacto"> 
<div class="row">
<div id="form-column" class="col-xs-12 col-sm-6 col-md-6 col-lg-6 col-sm-push-3 col-md-push-3 col-lg-push-3">
<div class="form-group">
<label for="name" class="sr-only">Nombre:</label>
<input type="textbox" placeholder="ingrese su nombre" name="name" id="name" class="form-control">
<div id="nameRequiredError" class="alert alert-danger" role="alert">El nombre es obligatorio.</div>
<div id="nameFormatError" class="alert alert-danger" role="alert">Solo se permiten letras y puntos.</div>
</div>
<div class="form-group">
<label for="email" class="sr-only">Correo electr&oacute;nico</label>
<input type="email" placeholder="ingrese su correo electr&oacute;nico" name="name" id="email" class="form-control">
<div id="emailRequiredError" class="alert alert-danger" role="alert">El direcci&oacute;n de correo electr&oacute;nico es obligatoria.</div>
<div id="emailFormatError" class="alert alert-danger" role="alert">Ingrese un correo electr&oacute;nico v&aacute;lido.</div>
</div>
<div class="form-group">
<label for="message" class="sr-only"></label>
<textarea name="" id="message" cols="30" rows="10" class="form-control" placeholder="Escriba su mensaje..." sizable="false"></textarea>
<div id="messageRequiredError" class="alert alert-danger" role="alert">Ingrese un mensaje para enviar.</div>
<div id="messageFormatError" class="alert alert-danger" role="alert">El mensaje no tiene nig&uacute;n caracter alfanum&eactue;rico.</div>
</div>
</div>
</div>
<div class="row">
<div id="form-column" class="col-xs-6 col-sm-3 col-md-3 col-lg-3 col-xs-push-6 col-sm-push-6 col-md-push-6 col-lg-push-6">
<submit class="btn btn-primary form-control"> Enviar &gt;&gt; </submit>
</div>
</div>
</form>

我想在输入失去焦点时验证数据输入,但我还没有捕获焦点。我尝试了所有这些:

$('#name').blur(function(event) {
alert("blur");
});

$('#name').focusout(function(event) {
alert("focusout");
});

// $('#name').live('focusout', function(){
// alert("live(focusout)");
// });

// $('#name').live('blur', function(){
// alert("live(blur)");
// });

$('#name').trigger('focusout', function(){
alert("trigger(focusout)");
});

$('#name').trigger('blur', function(){
alert("trigger(blur)");
});

$('#name').on('focusout', function(){
alert("on(focusout)");
});

$('#name').on('blur', function(){
alert("on(blur)");
});

但是这些不起作用,有人知道为什么吗?我快疯了!感谢所有阅读本文的人!

最佳答案

您的代码似乎在 JS Fiddle http://jsfiddle.net/dfkg7dha/2/ 中工作正常

但请尝试在 ready 函数中添加事件处理程序。仅当 DOM 准备好执行 JavaScript 时,此处的代码才会运行。

$(document).ready(function () {
$('#name').blur(function(event) {
alert("blur: perform validation here");
});
});

为了保持理智,请确保页面上引用了 JQuery JavaScript。

关于javascript - $(input).blur() & $(input).focusout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29168108/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com