如何在javascript中使用切换条件?
我想在 JavaScript 代码中使用 switch 条件。但我不知道怎么办?请帮助我做到这一点..提前致谢
I want to use switch condition in JavaScript code. but i dont know how? please help me to do this.. thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://www.w3schools.com/js/js_switch.asp
http://www.w3schools.com/js/js_switch.asp
你的问题没有太多细节,但无论如何我都会尽力提供帮助 - 但在不了解完整情况的情况下,很难给你一个明确的答案。
我假设您想要处理单击按钮时的重定向,但有一些条件吗?
通常您会使用一个简单的 case 语句来处理这个问题(如果只有两个条件,则使用 if/else ),如下所示(使用 jQuery 进行事件绑定):
You don't have a lot of detail in your question but I'll try to help regardless - but without knowing the full scenario its a bit hard to give you a definitive answer.
I'm going to assume you want to handle a redirection on a button click, but with some conditions?
Usually you would use a simple case statement to handle this (or an if/else if there is only two conditions), such as the following (using jQuery for event bindings):
阅读switch
对
大小写值没有限制 类型。
您可以在 JavaScript 中使用“字符串”大小写值
您可以添加重复的大小写值。无论是否重复,都会识别第一个匹配的大小写值。
Read switch
No restriction on
case value
type.You can use "string" case value in JavaScript
You can add duplicate case value. The first matching case value is recognized, regardless of duplicates.