簡體   English   中英

Google App Engine的HTML下拉框

[英]HTML drop-down box with Google App Engine

我正在創建一個用Python編寫的Google App Engine網絡應用程序,我想創建一個下拉框,以顯示與用戶可以選擇的書頁相對應的不同值。 我希望下拉框的作用是將用戶定向到與此鏈接對應的頁面:

<a href='/viewpage/{{bookpage.key}}'>{{ bookpage.page }} </a>

“ bookpage”實體傳遞給html

謝謝!

大衛

使用跳轉菜單 是一個非常簡單的實現。

基本上,您將只添加一些JavaScript,而不是編寫標簽,而是編寫一個選項:

<option value='/viewpage/{{bookpage.key}}'>{{ bookpage.page }} </option>

<option value='/viewpage/{{bookpage.key.id}}'>{{bookpage.page}}</option>怎么樣?

我希望這不是一個愚蠢的答案。

我不熟悉google-app-engine,但是以下javascript似乎可以滿足您的要求。 python可以在服務器端生成數組變量,然后其他所有東西都可以正常工作。 我包括了硬編碼的數組,因此您可以看到發生了什么,但是您可以用python代碼替換數組(假設bookpage是某種字典):

i = 0
for bp in bookpage.keys():
    print("mysites["+str(i)+"] = "+ bookpage[bp])+";"
    print("sitenames["+str(i)+"] = "+sitenames[bp])+";"
    i+=1

<html>
<body>
<script type="text/javascript">
var mysites= new Array();
    mysites[0] = "http://www.google.com";   //Generate this line with python
    mysites[1] = "http://www.bing.com";     //Generate this line with python
    mysites[2] = "http://www.yahoo.com"; //Generate this line with python
var sitenames = new Array();
    sitenames[0] = "Google";       //Generate this line with python
    sitenames[1] = "Bing";           //Generate this line with python
    sitenames[2] = "Yahoo";       //Generate this line with python
function changeLink(){
    var index = document.getElementById("theselect").selectedIndex
document.getElementById("thelink").innerHTML=index;
    var newlink = mysites[index];
    var newstring = sitenames[index];
    document.getElementById("thelink").href=newlink;
    document.getElementById("thelink").innerHTML=sitenames[index];
}
</script>
<select id="theselect" onclick="changeLink()">
  <option>Google</option>
  <option>Bing</option>
  <option>Yahoo</option>
</select>
 <br />
<a id="thelink" href="http://www.google.com" > Google </a>
</body>
</html>

單擊選項框將調用changeLink()函數,該函數然后更改鏈接和標記的內部html。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM