js中怎么设置输入框按取消就能退出输入框
<!doctypehtml><html><head><metacharset="utf-8"><title>无标题文档</title></head><body><scri...
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<script language="javascript">
def()
function def(){
var i=""
while (i != "123"){i = prompt("Please enter the correct password")}
alert("Welcome!");
}
</script>
</body>
</html>
这段代码无论怎么按取消都是停留在输入框,要怎么改才能按取消退出输入框呢?求大神指教 展开
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<script language="javascript">
def()
function def(){
var i=""
while (i != "123"){i = prompt("Please enter the correct password")}
alert("Welcome!");
}
</script>
</body>
</html>
这段代码无论怎么按取消都是停留在输入框,要怎么改才能按取消退出输入框呢?求大神指教 展开
2个回答
展开全部
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<script language="javascript">
def()
function def() {
var i = ""
while (i != null && i != "123") {
i = prompt("Please enter the correct password");
}
alert("Welcome!");
}
</script>
</body>
</html>
追问
能不能按了“取消”而不会提示“welcome!”呢?
追答
alert("Welcome!");前在加一个判断,判断i是不是null
展开全部
<html>
<head>
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
function def()
{
var i=""
while (i != "123")
{
i = prompt("Please enter the correct password","");
if(null==i)
{
break;
}
}
if(null!=i)
{
alert("Welcome!");
}
}
def();
</script>
</body>
</html>
<head>
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
function def()
{
var i=""
while (i != "123")
{
i = prompt("Please enter the correct password","");
if(null==i)
{
break;
}
}
if(null!=i)
{
alert("Welcome!");
}
}
def();
</script>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询