有人可以帮我弄这个吗?我是 javaScript 新手,无法让我的 onblur 或 onfocus 功能正常工作。这是 HTML 代码和 .JS 代码的片段。我在结束 body 标记的右下方和 head 标记中调用了我的 script.js,以确保不是这种情况......
HTML
<label for="name">Full Name</label>
<input type="text" id="name" name="fullname" value="First Name" />
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phonenumber" />
JavaScript
function prepareEventHandlers() {
var firstNameField = document.getElementById("name");
var phoneField = document.getELementsById("phone");
firstNameField.onfocus = function() {
if (firstNameField.value = "First Name") {
firstNameField.value = " ";
}
};
firstNameField.onblur = function() {
if (firstNameField.value == " ") {
firstNameField.value = "First Name";
}
};
}
window.onload = function() {
prepareEventHandlers();
}