简体   繁体   中英

window.prompt stop working when adding function

var user = window.prompt("Welcome to the Vacation Planner. Please enter yourname");
document.getElementById("greeting").innerHTML += ", " + user;
var enterDays = document.getElementById("enterDays");
/*
function.calculateDays(){
    var dayMessage = document.getElementById("dayMessage");
    if(enterDays <4){
        dayMessage.innerHTML = "Short trips are always worth it!";
        }
    else if(enterDays<7){
        dayMessage.innerHTML = "Cool, you'll be there for a week"
        }
    else{
        dayMessage.innerHTML = "You'll have plenty of time to relax and have fun!"
        }
}*/
enterDays.onclick = calculateDays;

When I enter this code, the window.prompt work correctly. But when I uncomment the function.calculateDays, the window.prompt stop working. Can anybody explain why is it happening and how to solve it? Thanks a lot!!!

function.calculateDays是无效的语法,并且会引发语法错误,该错误将阻止将来的代码调用,要对其进行修复,请用function calculateDays替换它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM