我的代码相当重复,当我自己尝试DRY*
时,我失去了一些功能。我是新来的,因此不胜感激。
这是我的代码:
document.getElementById('spe').addEventListener('keyup', function() {
var kitten = document.getElementById('spe').value;
kitten = kitten.toLowerCase();
if (kitten.search('qwe') !== -1) {
alert('potential watchlist');
}
if (kitten.search('americredit') !== -1) {
alert('potential watchlist');
}
if (kitten.search('bay view') !== -1) {
alert('potential watchlist');
}
if (kitten.search('nationwide equ') !== -1) {
alert('potential watchlist');
}
if (kitten.search('the moss ') !== -1) {
alert('potential watchlist');
}
if (kitten.search('kurt gei') !== -1) {
alert('potential watchlist');
}
if (kitten.search('haier') !== -1) {
alert('potential watchlist');
}
if (kitten.search('objekts') !== -1) {
alert('potential watchlist');
}
document.getElementById('spe').value = kitten;
},false);
* DRY: Don't Repeat Yourself