Javascript for replacing an abreviation by his equivalent

前端 未结 5 789
情话喂你
情话喂你 2021-01-26 05:00

I met some trouble with a javascript.

In fact I have in my database many records that are abreviations and ther equivalent,

for example, replace tel => telephon

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-26 05:37

    This should work:

    $('#tags').keyup(function(e){
        var code = e.which ? e.which : e.keyCode;
        var input = this.value;
        if (input.indexOf('tel') != -1) {
           this.value = this.value.replace(/\btel\b/gi,'telephone');
    
        }
    
    });
    

    Here is a fiddle

提交回复
热议问题