function clean(e){
var textfield = document.getElementById(e);
var regex = /[^a-z 1-9 ,.!?-`'"()\r\n ]/gi;
var wrongWords = new Array("can't", "I", "won't");
var rightWords = new Array("can not", "people", "will not");
var x = 0
if(textfield.value.search(regex) > -1) {
document.getElementById('status').innerHTML = "We found invalid characters";
textfield.value = textfield.value.replace(regex, "");
}
while(textfield.value.search(wrongWords) === true){
textfield.value = textfield.value.replace(wrongWords[x], rightWords[x]);
x++;
}
}
while語句有什麼問題。我怎樣才能使它工作?在JavaScript中查找和替換textarea中的單詞
有什麼實際問題? – likeitlikeit 2013-05-06 21:34:24
歡迎來到Stack Overflow。這些問題的答案取決於代碼*應該*做什麼(你沒有描述)。下一次,請包括代碼執行的內容以及它與預期的不同之處(實際結果與預期結果)的簡要說明。幫助別人來幫助你;-) – Leigh 2013-05-07 01:12:17