我想在使用struts2标记单击按钮时动态创建选择列表?
我想在单击按钮时动态创建下拉列表,下拉列表中选择的值应插入数据库。下拉列表应位于Struts2标记中我想在使用struts2标记单击按钮时动态创建选择列表?,struts2,Struts2,我想在单击按钮时动态创建下拉列表,下拉列表中选择的值应插入数据库。下拉列表应位于Struts2标记中 function addDropDown(parent){ var myselect = document.createElement("select"); myselect.setAttribute("name","someName"); myselect.onchange=function(){ submitvalue(this.value)
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);
}
单击按钮,以某个父元素(form或div)为参数调用此函数。选择下拉列表中的任何元素时,都会调用函数submitvalue(),在那里执行数据库提交操作(使用ajax或您未提及的其他方法提交)。我还注意到您提到下拉列表应该在struts2标记中,我不知道为什么即使是静态struts2标记在执行时也会更改为html标记