2010-01-09 38 views
2

我想問一下博主中是否有elseif聲明? 我所見過的只有if和else但elseif。博客b:如果聲明

如果沒有任何elseif語句,我怎麼能給if語句多個條件?

例如,在這種情況下,我有3作者AB和C.最近d和E加入了我們,我有一個代碼,使得如果作者是AB或C,它將發佈它們各自的圖像

<b:if cond='data:post.author == &quot;Author-A&quot;'> 

<img class='ava' height='100' 
src='img-URL-1' 
width='100'/> 

</b:if> 
<b:if cond='data:post.author == &quot;Author-B&quot;'> 

<img class='ava' height='100' 
src='img-URL-2' 
width='100'/> 

</b:if> 

等等。 但如果作者不是AB或C,CSS會搞砸我的博客帖子,所以我想用elseif來做這件事,如果elseif在這種情況下不可用,我想在上面的代碼後加上這個代碼

<b:if cond='data:post.author != &quot;Author-A&quot && &quot;Author-B&quot && &quot;Author-C&quot;'> 

<img class='ava' height='100' 
src='else-IMG-URL' 
width='100'/> 

</b:if> 

但我試過了,它似乎不工作,它說& &是無效的。任何想法我應該把用作OR?

回答

1

在僞翻譯你在邏輯上,而要做到以下幾點:

if (author != A && author != B && author != C) 

,因此你嘗試過什麼:

if (author != A && B && C) 
0

也許你需要指定&&&amp;&amp;

這應該解決您收到的錯誤消息。您可能仍然需要修復BalusC指出的邏輯問題。

+0

謝謝,是的,我忘了這一點,我添加了什麼BalusC指出,但它仍然看起來博主沒有按」當我有這個時,就允許'!='這個博客文章沒有出現。 – Crays 2010-01-09 04:55:39

+0

你確定嗎?據此看來,支持!=:http://www.google.com/support/blogger/bin/answer.py?hl=zh_CN&answer=46995 – 2010-01-11 16:18:57

1

,如果你想要做一個邏輯結束-ING然後使用此格式:

<b:if cond='condition 1'> 
<b:if cond='condition 2'> 
contents go here 
</b:if> 
</b:if> 
1
<b:if cond='condition1'> 
    Do something for 1 
<b:else/> 
    <b:if cond='condition2'> 
     Do something for 2 
    <b:else/> 
     <b:if cond='condition3'> 
      Do something for 3 
     <b:else/> 
      Do something for others 
     </b:if> 
    </b:if> 
</b:if>