我有一個非常基本的代碼。但是,我無法通過單擊id(userYOB)來清除年份。該代碼僅適用於要求年份的代碼。它不僅僅是清除,但我也想要一旦警報被點擊確定後重新放置佔位符。無法清除輸入域
感謝您的幫助。
[小提琴] http://jsfiddle.net/vineetgnair/j8zjjj9r/26/
var d = new Date();
var currentYear = d.getFullYear();
function test() {
var userYearOfBirth = document.getElementById("userYOB").value;
var authorisedAge = 19;
var currentAge = parseInt(currentYear - userYearOfBirth);
//console.log(currentAge);
if (currentAge < authorisedAge) {
alert("You are not authorised to visit the site");
document.getElementById("userYOB").value = " ";
} else {
alert("Welcome to the site!");
userYearOfBirth = " ";
}
}
如果要清除年份的文本框並顯示佔位符/水印文本,則將該值設置爲空字符串document.getElementById(「userYOB」)。value =「」; – user2321864 2014-08-31 14:13:30