0

我正在使用实时验证插件来验证我的表单。而当表单提交时,插件会在<input>之后添加这行代码:

<span class=" LV_validation_message LV_valid">Ok</span>

没关系,但是当我提交表单时,我想为下一个用户重置表单。这是我的代码:

$('#myForm').on('submit',function(e){
    e.preventDefault();
    var inputsValid = email.form.onsubmit();//apparently this checks that all fields are valid: name, phone, email
    if(inputsValid){
        $(this).remove('.LV_validation_message');
        //do stuff like send data to backend here...
        hideMyForm();
    }
});

正如你所看到的,一旦我验证了这些字段是正确的,我将尝试通过删除类“LV_validation_message”的元素来删除经过验证的消息。之后,我将隐藏表格。下次下一个用户访问该页面时,我将再次显示该表单 - 只有该$(this).remove('.LV_validation_message')行不起作用,第二个用户看到验证消息卡在表单上,​​即使输入字段已重置并且为空.

我从 开始$('#myForm').submit,但将其更改为$('#myForm').on('submit'),因为我知道<span class=" LV_validation_message LV_valid">Ok</span>是动态添加的。我尝试使用$(this).remove('.LV_validation_message'), $('.LV_validation_message'.remove(), 甚至$('.LV_validation_message'.html("")- 使用 LV_validation_message 类更改元素,但无济于事。这些元素似乎完全不受 jQuery 的控制。

有人可以向我提供一些提示或想法,说明为什么我根本无法删除这些元素吗?这是有问题的表格,以防万一:

<form id="myForm" autocomplete="off" class="tcenter">
    <label name="name">Name</label>
    <input id="name" type="text" value="" autocomplete="off"><div class="LV-arrow-left-red">   </div><div class="LV-arrow-left-green"></div><br>
    <label name="phone">Phone</label>
    <input id="phone" type="text" value="" autocomplete="off"><div class="LV-arrow-left-red"></div><div class="LV-arrow-left-green"></div><br>
    <label name="email">Email</label>
    <input id="email" type="text" value="" autocomplete="off"><div class="LV-arrow-left-red"></div><div class="LV-arrow-left-green"></div><br>
    <label><!-- Empty tag; to maintain layout --></label>
    <input class="ui-keyboard-button" type="image" width="297" height="64" alt="Submit">
</form> 

提前致谢。

4

2 回答 2

0

尝试$('.LV_validation_message').val("")

或者错误可能是输入标签关闭不当,应该是

 <input id="name" type="text" value="" autocomplete="off"><div class="LV-arrow-left-red">   </div><div class="LV-arrow-left-green"></div></input>
于 2014-01-15T05:10:18.903 回答
0

这似乎有效 $('.LV_validation_message').remove()

在http://jsfiddle.net/4c8c4/上查看我的小提琴

于 2014-01-15T05:10:54.307 回答