如何使用带有javascript函数的超链接 函数tryDoor(){ 如果(hasKey==true){ 警惕(“你开门”); }否则{ 警报(“车门已锁定,请找到钥匙”);
如何使hasKey==true且门打开时,用户将被带到另一个网页。我尝试使用超链接解决此问题失败如何使用带有javascript函数的超链接 函数tryDoor(){ 如果(hasKey==true){ 警惕(“你开门”); }否则{ 警报(“车门已锁定,请找到钥匙”);,javascript,html,css,Javascript,Html,Css,如何使hasKey==true且门打开时,用户将被带到另一个网页。我尝试使用超链接解决此问题失败 谢谢。我想您对doorIsOpen有一个单独的var <img id="corridor" src="Images/Corridor.jpg" class="centre" usemap="#map1"> <img id = "key" src=&qu
谢谢。我想您对
doorIsOpen
有一个单独的var
<img id="corridor" src="Images/Corridor.jpg" class="centre" usemap="#map1">
<img id = "key" src="Images/key.png" onclick="pickupKey()">
<map name="map1">
<area onclick="tryDoor()" id="door1" onblur="door1.focus()" autofocus shape="rect" coords="830,240,750,350"/>
</map>
function tryDoor(){
if (hasKey == true) {
alert("you open the door");
}else{
alert("The door is locked find a key");
location.href=“somewhere\u else.html”
这是否回答了您的问题?
var doorIsOpen = false;
if (hasKey == true) {
if(!doorIsOpen) {
alert("you open the door");
doorIsOpen = true;
} else {
document.location.href = "www.google.com";
}
} else {
alert('door is locked');
}