jQuery提示插件和$ _POST的问题

时间:2011-07-06 19:57:44

标签: php jquery

我正在使用remy sharp's hint plugin

<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);
     });
 });

2 个答案:

答案 0 :(得分:3)

当输入的表单被提交时,插件会删除提示,遗憾的是您没有提交表单,而是通过$.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);
     });
 });

答案 1 :(得分:0)

你不能。

只需在代码中添加if语句:

if($_POST['names'] == 'hint' ) {
   //DONT USE IT!!
}