0

这个问题得到了回答。但是stackoverflow不会让我问其他问题。任何人都可以帮忙吗?

4

1 回答 1

3

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

//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
于 2012-12-21T18:45:25.197 回答