Javascript用他的等价替换abreviation [英] Javascript for replacing an abreviation by his equivalent
本文介绍了Javascript用他的等价替换abreviation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用javascript时遇到了一些麻烦。
I met some trouble with a javascript.
事实上,我在我的数据库中有许多记录,这些记录是相同的,等等,
In fact I have in my database many records that are abreviations and ther equivalent,
例如,替换tel =>电话等......
for example, replace tel => telephone etc...
所以我有这个功能
$('#tags').keyup(function(e){
var code = e.which ? e.which : e.keyCode;
console.log(code);
if (code == 'tel'){
var input = this.value;
input = input.substr(0, input.length -1);
console.log(input);
input += 'tel';
this.value = input;
}
});
Actualy这不起作用麻烦的是我没有aby错误
javascript的控制台。
Actualy this does not work the trouble is that I do not have aby mistakes in the console of javascript.
非常感谢Anykind的帮助。
Anykind of help will be much appreciated.
亲切的问候。
SP。
推荐答案
这应该有效:
$('#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');
}
});
这是小提琴
这篇关于Javascript用他的等价替换abreviation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文