Remove a given string from an input value using jQuery

前端 未结 3 1629
我在风中等你
我在风中等你 2021-01-25 08:32

I have a hidden field with three integer values, example:


I want to use jQuery to remove a giv

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-25 08:57

    Basically the same as @Shaz answer but perhaps a little cleaner. This uses a function that returns the val to use. See the API docs at http://api.jquery.com/val/

    $('input').val(function(index, val){
        return val.replace('10', '').trim();
    });
    

    To handle the possible trailing space after your integer:

    val.replace(/10 ?/, '').trim()
    

提交回复
热议问题