开发者

jQuery remove spaces on blur not working

The replace function I'm using works as I've tested it in the console but it does not work at all on blur. How can I fix that?

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


you have removed the spaces but u have not assigned them any where :)

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


I'm using:

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


You can try this.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜