任何人都可以帮助我在 jQuery 中进行修剪吗?

Can anyone help me regarding trimming in jQuery?

我正在学习 jQuery 但我不知道如何在 jQuery 中使用 trim。

// Cut trailing whitespaces 'foo bar    '

// cut leading nowhitespaces '    foo bar'

// now: put input back into inputfield.
inputField.val('foo bar');


// Check if inputField.val() contains regex.
// inputField.val() will give you a "string"

// if true - do something

非常感谢,

试试这个:

var str = "   foo bar  ";
    str.trim();
    if (str.match(regex) 
    {
       ---do something---
    }