首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果q等于nothing,则s等于nothing Javascript

如果q等于nothing,则s等于nothing Javascript
EN

Stack Overflow用户
提问于 2012-12-22 02:42:06
回答 1查看 176关注 0票数 0

这个问题已经得到了回答。但是stackoverflow不会让我问其他问题。有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-22 02:45:25

声明s并将其默认设置为空字符串。如果q1不是nothing,则为s赋值。否则,s仍为空字符串。在稍后的代码中,您可以将文本框设置为使用s填充,如果q1为空,则s也将为空,因此不会在那里显示任何内容。

代码语言:javascript
复制
//declare s and set it to default to an empty string
var s = ''
//make sure q1 is defined and not null
if (q1 != undefined && q1 != null)
   //if q1 is not empty, then set it equal to '_'+n1+'. '+q1, 
   //otherwise s will be an empty string
   if (q1 != '')
       s = '_'+n1+'. '+q1
//if s is empty you can do something, 
//OR you can just set your input value to equal s
if (s == '')
    //do some stuff here
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13995478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档