Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想在使用struts2标记单击按钮时动态创建选择列表?_Struts2 - Fatal编程技术网

我想在使用struts2标记单击按钮时动态创建选择列表?

我想在使用struts2标记单击按钮时动态创建选择列表?,struts2,Struts2,我想在单击按钮时动态创建下拉列表,下拉列表中选择的值应插入数据库。下拉列表应位于Struts2标记中 function addDropDown(parent){ var myselect = document.createElement("select"); myselect.setAttribute("name","someName"); myselect.onchange=function(){ submitvalue(this.value)

我想在单击按钮时动态创建下拉列表,下拉列表中选择的值应插入数据库。下拉列表应位于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);

}
单击按钮,以某个父元素(form或div)为参数调用此函数。选择下拉列表中的任何元素时,都会调用函数submitvalue(),在那里执行数据库提交操作(使用ajax或您未提及的其他方法提交)。我还注意到您提到下拉列表应该在struts2标记中,我不知道为什么即使是静态struts2标记在执行时也会更改为html标记