gpt4 book ai didi

javascript - 为什么这个 if 语句不起作用?

转载 作者:行者123 更新时间:2023-11-30 21:03:40 25 4
gpt4 key购买 nike

<分区>

我正在测试一行代码,它检查变量是否为空。如果它为空,则会弹出提示。但是即使变量有东西,还是会弹出提示。

function myFunction(){

if (site == null || variable == undefined) {
var site = prompt("Please enter a valid url:", "http://");
document.cookie = 'Your bookmark is: '+ site;
alert(unescape(document.cookie));
document.getElementById("p1").innerHTML = '<a class="txt2" href="' + site + '" target="myframe">' + site + '</a>';
}

else {
alert('yey its working');
}
}
<a class="txt2" id="p1" onclick="myFunction()">Button</a>

代码在设置变量之后起作用,在加载页面之前再次弹出提示。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com