Trim spaces from start and end of string

前端 未结 14 1432
情歌与酒
情歌与酒 2020-11-28 01:56

I am trying to find a way to trim spaces from the start and end of the title string. I was using this, but it doesn\'t seem to be working:

title = title.repl         


        
14条回答
  •  北海茫月
    2020-11-28 02:45

    If using jQuery is an option:

    /**
     * Trim the site input[type=text] fields globally by removing any whitespace from the
     * beginning and end of a string on input .blur()
     */
    $('input[type=text]').blur(function(){
        $(this).val($.trim($(this).val()));
    });
    

    or simply:

    $.trim(string);
    

提交回复
热议问题