2011-04-08 25 views

回答

0
function addDropDown(parent){ 

     var myselect = document.createElement("select"); 
     myselect.setAttribute("name","someName"); 
     myselect.onchange=function(){ submitvalue(this.value) }; 


     theOption=document.createElement("OPTION"); 
     theText=document.createTextNode("text gere1"); 
     theOption.appendChild(theText); 
     theOption.setAttribute("value","value here1"); 
     myselect.appendChild(theOption); 

     theOption=document.createElement("OPTION"); 
     theText=document.createTextNode("text gere2"); 
     theOption.appendChild(theText); 
     theOption.setAttribute("value","value gere2"); 
     myselect.appendChild(theOption); 

     theOption=document.createElement("OPTION"); 
     theText=document.createTextNode("text gere3"); 
     theOption.appendChild(theText); 
     theOption.setAttribute("value","value gere3"); 
     myselect.appendChild(theOption); 

     parent,appendChild(myselect); 

} 

調用這個函數的onClick您的按鈕以及一些父元素(形式或格)作爲argument.The功能submitvalue()將在下拉列表中的任何元素的選擇調用,做你的數據庫提交的行動有(提交使用ajax或任何你使用的,因爲你沒有提到它)。我也注意到你已經提到下拉應該在struts2標籤中,但我不知道爲什麼,即使靜態struts2標籤在執行時被改爲html標籤。

相關問題