你的“输入”是这样的吗?<input value="<?php echo $errorMessage; ?>"/>我建议使用“占位符”属性,<input placeholder="<?php echo $errorMessage; ?>"/>或者如果你想继续使用 JS,var inputBox = document.getElementById(INPUT_BOX_ID);inputBox.oninput = function(){ inputBox.value = inputBox.value.replace(" - Confrim valid surname",""); // Simply remove the Error Text you've echoed inputBox.oninput = null; // Delete the function so user can type something}// Its still not detecting the valid surname, but its removes the " - Confrim valid surname"