jQuery删除模糊不工作空间

问题描述:

我使用的替换函数工作,因为我已经在控制台中测试它,但它根本不工作模糊。我该如何解决这个问题?jQuery删除模糊不工作空间

<script type="text/javascript"> 
    //Ensure spaces are not entered between tags 
    jQuery(document).ready(function(){ 
     jQuery('#item_keywords').blur(function(){ 
      $(this).val().replace(/^\s+$/,""); 
     }); 
    }); 
</script> 
+0

什么是当前结果?它是否做任何事情?你有没有使用萤火虫/镀铬控制台来查看是否有任何错误? – gnur 2011-02-18 11:33:29

+0

请给出一个你想要达到什么样的例子,包括一些标记,给出的答案是正确的,如果它是一个正常的输入标签,如果这对你不起作用,那么别的错误,人们无法猜测。 .. – 2011-02-18 11:49:24

你已经删除了空间,但ü没有为其指定的任何地方:)

jQuery(document).ready(function(){ 
     jQuery('#item_keywords').unbind('blur').bind('blur',function(){ 
      $(this).val($(this).val().replace(/^\s+$/,"")); 
     }); 
    }); 

我使用:

 jQuery(document).ready(function(){ 
      jQuery('#business_email').unbind('blur').bind('blur',function(){ 
       var a = $(this).val().trim(); 
       $(this).val(a + '.'); 
       $(this).val(a); 
      }); 
     }); 

你可以试试这个。

$(document).ready(function(){ 
    $("#mytextbox").blur(function(){ 
     $(this).val($(this).val().replace(/\s/g,'')); 
     console.log($(this).val()); 
    }); 
});