var str1 = document.getElementById('string').value;
var str = str1.toUpperCase();
function correctstring() {
for (var i=0;i < str.length ; i++) {
if(str[i]==='H'){str[i]='R';}
else if(str[i]==='V'){str[i]='L';}
else if (str[i] === 'G'){ str[i]='F'; }
else {atert('the string has a wrong input, Please enter the right chars for english(R,L,F) for swedish (H,V,G)');
}
}
}
correctstring();
答案 0 :(得分:0)
字符串在JS中不被视为数组,只需将其转换为数组然后再投射回来:
st = str1.split("");
//Your code
str1 = st.join("")
不要忘记在循环中将 str1 更改为 st