2012-12-21 57 views

回答

3

聲明並默認將其設置爲空字符串。如果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 
+1

一個很好的答案一般由一些解釋代碼片段組成。 – jbabey

+0

不,沒有什麼幫助。我只是不能解釋我想要的。我希望它完全忽略s,如果q1等於什麼也不是。 – DustinH

+0

我試試這個謝謝。 – DustinH

相關問題