我正在使用remy sharp的提示插件.
<input type="text" title="hint" name="names" class="input" />
Run Code Online (Sandbox Code Playgroud)
但是当我发布表单而不填写字段时,输入仍然有
$_POST['names'] = 'hint';
Run Code Online (Sandbox Code Playgroud)
我该如何防止这个问题?
提前致谢.
编辑:jQuery代码:
$(".input").hint();
$(".lSubmit").click(function(e){
e.preventDefault();
$.post('form.php',decodeURIComponent($("#forms").serialize()) , function(data) {
$('.result').html(data);
});
});
Run Code Online (Sandbox Code Playgroud)
当提交输入的表单时,该插件会删除提示本身,不幸的是您没有提交表单,而是通过$.post.
最简单的方法可能是在根据标题提交输入之前检查输入的值,如果它们相同则清除它:
$(".lSubmit").click(function(e){
// clear inputs that still have the hint as value
$('.input').each(function() {
if($(this).val() == $(this).attr('title')) {
$(this).val("");
}
});
e.preventDefault();
$.post('form.php',decodeURIComponent($("#forms").serialize()) , function(data) {
$('.result').html(data);
});
});
Run Code Online (Sandbox Code Playgroud)