我正在使用remy sharp的hint插件。
<input type="text" title="hint" name="names" class="input" />
但是当我发布表单而不填写字段时,输入仍然有
$_POST['names'] = 'hint';
如何防止这个问题?
提前感谢。
jQuery代码:$(".input").hint();
$(".lSubmit").click(function(e){
e.preventDefault();
$.post('form.php',decodeURIComponent($("#forms").serialize()) , function(data) {
$('.result').html(data);
});
});
插件在提交表单时删除提示本身,不幸的是您没有提交表单,而是通过$.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);
});
});
你不能。
只需在代码中添加一个if语句:
if($_POST['names'] == 'hint' ) {
//DONT USE IT!!
}