2016-08-30 41 views
0

我有這種形式在我的HTML:HTML形式返回在Firefox和IE什麼(OK在Chrome)

<form action="/vcontent?topic={{ topic.name }}" method="post"> 
    {% if user and user.email in c.users_up %} 
    <input type="image" src="icons/thumb-up.png" alt="Up!" name = "vote" value = "up" /> 
    {% else %} 
    <input type="image" src="icons/thumb-up_gray.png" alt="Up!" name = "vote" value = "up" /> 
    {% endif %} 
    {% if user and user.email in c.users_down %} 
    &nbsp;<input type="image" src="icons/thumb-down.png" alt="Down!" name = "vote" value = "down" /> 
    {% else %} 
    &nbsp;<input type="image" src="icons/thumb-down_gray.png" alt="Down!" name = "vote" value = "down" /> 
    {% endif %} 
    <input name= "content_key" type="hidden" value="{{ c.key.urlsafe() }}"> 
</form> 

當我嘗試給予好評Chrome版的內容,它工作正常。當我得到的價值:

vote = self.request.get('vote') 

我得到「向上」或「向下」,因爲它應該是。

但是,當我在IE和Firefox上做同樣的事情時,我得到一個空字符串。

(HTML中的if/else語句表示如果用戶還沒有對該特定內容進行投票,該圖標顯示爲灰色,否則爲黑色)。

我正在使用Jinja2作爲模板引擎的Google App Engine上。

+0

您知道' mplungjan

+0

是的,它的工作原理就是這樣。這是一個按下時提交表單的圖標。但它應該與投票=「上」或投票=「下」,而不是與投票=「」。 –

回答

0

試試這個。相反,使用圖像,使用按鈕:

<style>button {height:32px; width:32px;}</style> 

<form action="/vcontent?topic={{ topic.name }}" method="post"> 
    {% if user and user.email in c.users_up %} 
    <button type="submit" style="background: url(icons/thumb-up.png)" title="Up!" name="vote" value="up" /> 
    {% else %} 
    <button type="submit" style="background: url(icons/thumb-up_gray.png)" title="Up!" name="vote" value="up" /> 
    {% endif %} 
    {% if user and user.email in c.users_down %} 
    &nbsp;<button type="submit" style="background: url(icons/thumb-down.png)" title="Down!" name="vote" value="down" /> 
    {% else %} 
    &nbsp;<button type="submit" style="background: url(icons/thumb-down_gray.png)" title="Down!" name="vote" value="down" /> 
    {% endif %} 
    <input name= "content_key" type="hidden" value="{{ c.key.urlsafe() }}"> 
</form> 
+0

謝謝!這是有效的,但糟糕的頁面上的圖標,我試圖調整它們與一些CSS,但它沒有奏效。 沒有任何方法可以使它與圖像而不是按鈕一起使用嗎? –

0

好吧,我想我的工作了,我張貼我的解決方案,誰就可能要做到這一點,這就是代碼:

<form action="/vcontent?topic={{ topic.name }}" method="post"> 
    {% if user and user.email in c.users_up %} 
    <input type="image" src="icons/thumb-up.png" alt="Up!" name = "vote" value = "up" /> 
    {% else %} 
    <input type="image" src="icons/thumb-up_gray.png" alt="Up!" name = "vote" value = "up" /> 
    {% endif %} 
    <input type="hidden" name = "vote" value = "up"/> 
    <input name= "content_key" type="hidden" value="{{ c.key.urlsafe() }}"> 
</form> 
<form action="/vcontent?topic={{ topic.name }}" method="post"> 
    {% if user and user.email in c.users_down %} 
    &nbsp;<input type="image" src="icons/thumb-down.png" alt="Down!" name = "vote" value = "down" /> 
    {% else %} 
    &nbsp;<input type="image" src="icons/thumb-down_gray.png" alt="Down!" name = "vote" value = "down" /> 
    {% endif %} 
    <input type="hidden" name = "vote" value = "down"/> 
    <input name= "content_key" type="hidden" value="{{ c.key.urlsafe() }}"> 
</form> 

我第一部分管理upvote的代碼基本上翻了一番,第二部分管理downvote。當我點擊一個圖標時,投票值被隱藏返回。 我認爲這是不可避免的加倍的代碼,否則你不能根據按下的圖標設置隱藏值的值。

相關問題