-1
我想動態創建下拉列表,當我點擊一個按鈕,下拉列表中選擇的值應該插入數據庫下拉列表應該在Struts2標籤中。我想動態創建選擇列表,當我點擊一個按鈕通過使用struts2標籤?
我想動態創建下拉列表,當我點擊一個按鈕,下拉列表中選擇的值應該插入數據庫下拉列表應該在Struts2標籤中。我想動態創建選擇列表,當我點擊一個按鈕通過使用struts2標籤?
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標籤。