双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

IE11不支持 onload吗?为什么我的问候语出不来

sunkess sunkess 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
onload:

function greetUser() {
if (navigator.cookieEnabled)
userName = readCookie("irock_username");


if (userName)
alert("Hello " + userName + ", I missed you.");
else
alert('Hello, I am your pet rock.');

}


IE 11始终不能执行 ,初学JS 。请指教,谢谢!



<head>
<title>iRock - The Virtual Pet Rock</title>

<script type="text/javascript" src="cookie.js"></script>

<script type="text/javascript">
var userName;

function resizeRock() {
document.getElementById("rockImg").style.height = (document.body.clientHeight - 100) * 0.9;
}

function greetUser() {
if (navigator.cookieEnabled)
userName = readCookie("irock_username");

//出现问题的地方
if (userName)
alert("Hello " + userName + ", I missed you.");
else
alert('Hello, I am your pet rock.');

}

function touchRock() {
if (userName) {
alert("I like the attention, " + userName + ". Thank you.");
}
else {
userName = prompt("What is your name?", "Enter your name here.");
if (userName) {
alert("It is good to meet you, " + userName + ".");
if (navigator.cookieEnabled)
writeCookie("irock_username", userName, 5 * 365);
else
alert("Cookies aren't supported/enabled in your browser, which means I won't remember you later. I'm sorry.");
}
}
document.getElementById("rockImg").src = "rock_happy.png";
setTimeout("document.getElementById('rockImg').src = 'rock.png';", 5 * 60 * 1000);
}
</script>
</head>

<body onload="resizeRock(); greetUser();" onresize="resizeRock();">
<div style="margin-top:100px; text-align:center">
<img id="rockImg" src="rock.png" alt="iRock" style="cursor:pointer" onclick="touchRock();" />
</div>
</body>
</html>


...全文
评论 3
收藏 已收藏
分享
返回顶部
sunkess
JavaScript 87,983 成员 224,681 内容