jQuery 删除模糊上的空格不起作用

发布于 2024-10-18 04:30:50 字数 351 浏览 8 评论 0原文

我正在使用的替换功能可以正常工作,因为我已经在控制台中对其进行了测试,但它在模糊时根本不起作用。我该如何解决这个问题?

<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>

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(function(){
        jQuery('#item_keywords').blur(function(){
            $(this).val().replace(/^\s+$/,"");
        });
    });
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天冷不及心凉 2024-10-25 04:30:53

我正在使用:

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

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);
            });
        });
↙温凉少女 2024-10-25 04:30:53

你可以试试这个。

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

You can try this.

$(document).ready(function(){
    $("#mytextbox").blur(function(){
        $(this).val($(this).val().replace(/\s/g,''));
        console.log($(this).val());
    });
});
Saygoodbye 2024-10-25 04:30:52

您已删除空格,但尚未将它们分配到任何位置:)

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

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+$/,""));
        });
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文