当if / if else语句为true时,继续执行函数。 [英] Stoping function from continueing when if/ if else statement is true.

查看:135
本文介绍了当if / if else语句为true时,继续执行函数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天厌倦了数学,决定写一个程序。迎接用户,如果用户有一个特定的名字,它会把他们带到一个网站,如果你不是其中一个用户,会发生不同的事情:


[HTML ]< html>

< head>

< script type =" text / javascript">


var fn;

var ln;

var hay;

var cn;

var dy;

var fs;


功能问候语()


{


fn =提示(你好,你的名字是什么?,alt ="你的名字")

alert("'这是一个好名字" +"" + fn +"!");


ln =提示("" +"" + fn +"," +"什么是你的姓氏?",alt ="你的姓氏")

提醒(很高兴见到你+&; + + fn +"" + ln +"!")


提醒(你知道我是你的电脑,但是你如果你愿意,可以给我一个名字。)


cn =提示(那么我的名字是什么?,alt =" computer)

alert(" " + cn +"," +我爱它!


hay = prompt("" +"" + fn +"," +"今天你好吗? ?",alt =" great")


if(hay ==" good")

{

警告(那太好了!)

}

else if(hay ==" fine")

{

alert(那太好了!)

}

else if(hay ==" great")

{

alert(那太棒了!)

}

否则如果(干草) ==awesome)

{

alert(那太好了!)

}

else if(hay ==" ok")

{

alert(那太好了!)

}

其他

{

警告(我希望你的日子好转!)

}


if(fn ==" User1"& ln ==" user1")

{

警报(很高兴见到你再来一次是User1 user1,这里是你的页面!")

top.window.location =" http://google.com" ;;

}

else if(fn ==" User2" &安培;&安培; ln ==" user2")

{

alert(很高兴再次见到你User2 user2,这里是你的页面!) >
top.window.location =" http://thescripts.com" ;;

}

else

{

alert(与你交谈非常棒!)

}


dy =提示(") ;你想再和我说话吗?",alt =" yes")


if(dy ==" yes")

{

问候();

}

否则if(dy ==" no")

{

alert("然后让我带你到你最喜欢的网站。)

fs =提示(请输入你最喜欢的网站不要以http开头: //或www。")

top.window.location =" http://" + fs +" ;

}

其他

{

alert(Bye)

}


}


< / script>

< / head>

< body>

< form>

< input type =" button"的onclick = QUOT;问候()" value ="你想跟我说话吗? />

< / form>

< / body>

< / html> [/ HTML]

只有一个问题,如果你是一个选定的用户,它会开始带你到那个站点,然后它会提示你输入dy变量,然后继续if ... else if ......之后呢。


如果你是其中一个用户,我怎么能阻止它继续?



谢谢,死亡

解决方案

只需添加一个

展开 | 选择 | Wrap | 行号



只需添加一个

展开 | 选择 | Wrap | 行号


嗨...


当然是;)...让我举个典型例子:


[HTML]< html>

< script type =" text / javascript">

function shift_value(){

var input_node = document.getElementById(''my_input_id'');

var div_node = document.getElementById(''my_div'');


var div_value = input_node.value;


div_node.innerHTML ='''';

div_node.innerHTML = div_value;

}

< / script>

< body>

< form action ="" ; name =" my_form">

< input type =" text"名称= QUOT; my_input" id =" my_input_id" />

< input type =" button" value =" shift to div" onclick =" shift_value();" />

< / form>

< div id =" my_div">< / div>

< / body>

< / html>

[/ HTML]

亲切的问候

I got bored in math today and decided to write a "program" that greets the user, and if the user has a certain name it will take them to a site, and if you''re not one of the users something different happens:

[HTML]<html>
<head>
<script type="text/javascript">

var fn;
var ln;
var hay;
var cn;
var dy;
var fs;

function greeting()

{

fn=prompt("Hello what''s your name?", alt="Your first name")
alert("That''s a great name" + " " + fn + "!");

ln=prompt("So" + " " + fn + "," + "what''s your last name?", alt="Your last name")
alert("Well it''s nice to meet you" + " " + fn + " " + ln + "!")

alert("As you know i''m your computer, but you can give me a name if you want to.")

cn=prompt("So what''s my name?", alt="computer")
alert(" " + cn + "," + "I love it!")

hay=prompt("So" + " " + fn + "," + "how are you today?", alt="great")

if (hay == "good")
{
alert("That''s great!")
}
else if (hay == "fine")
{
alert("That''s great!")
}
else if (hay == "great")
{
alert("That''s great!")
}
else if (hay == "awesome")
{
alert("That''s great!")
}
else if (hay == "ok")
{
alert("That''s great!")
}
else
{
alert("I hope your day goes better!")
}

if (fn == "User1" && ln == "user1")
{
alert("Nice to see you again User1 user1, here''s your page!")
top.window.location="http://google.com";
}
else if (fn =="User2" && ln == "user2")
{
alert("Nice to see you again User2 user2, here''s your page!")
top.window.location="http://thescripts.com";
}
else
{
alert("It''s been great talking with you!")
}

dy=prompt("Do you want to talk with me again?", alt="yes")

if (dy == "yes")
{
greeting();
}
else if (dy == "no")
{
alert("Then let me take you to you favorite site.")
fs=prompt("Please enter your favorite site do not start with http:// or www.")
top.window.location="http://" + fs + " ";
}
else
{
alert("Bye")
}

}

</script>
</head>
<body>
<form>
<input type="button" onclick="greeting()" value="Do you want to talk to me?" />
</form>
</body>
</html>[/HTML]
There''s only one problem, if you are one of the selected users, it starts to take you to that site, and then it prompts you for the dy variable, and continues with the if...else if......else after that.

So how can I stop it from continueing if you are one of the users?


Thanks, Death

解决方案

simply add a

Expand|Select|Wrap|Line Numbers


simply add a

Expand|Select|Wrap|Line Numbers


hi ...

of course it is ;) ... let me give you an typical example:

[HTML]<html>
<script type="text/javascript">
function shift_value() {
var input_node = document.getElementById(''my_input_id'');
var div_node = document.getElementById(''my_div'');

var div_value = input_node.value;

div_node.innerHTML = '''';
div_node.innerHTML = div_value;
}
</script>
<body>
<form action="" name="my_form">
<input type="text" name="my_input" id="my_input_id"/>
<input type="button" value="shift to div" onclick="shift_value();"/>
</form>
<div id="my_div"></div>
</body>
</html>
[/HTML]
kind regards


这篇关于当if / if else语句为true时,继续执行函数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆