开发者

jQuery remove spaces on blur not working

开发者 https://www.devze.com 2023-02-12 02:09 出处:网络
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?

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

精彩评论

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