<td class="addTd_L">
专家库
<span class="redstar">*</span>
</td>
<td class="addTd_R" colspan="3">
<span id="spanid">
s:select name="expert.expertBaseSortList[0].expertBaseId" list="expertBaseList" listKey="id" id="selectBase"
listValue="name" headerKey="0" headerValue="--请选择--"/>
</span>
<a href="#" οnclick="addExpertBaseSelect()">增加</a>
<div id="sortDiv1" style="float: left; width: 440px; height: 0px; border-width: 2px; ">
</div>
</td>
js代码
var num=1; function addExpertBaseSelect() { var string = '<img src="${URL_IMAGEPATH}icon_del.gif" style="cursor:hand;vertical-align: middle" οnclick="removeSort('+num+')" alt="删除"/> '; var option = document.getElementById("selectBase").innerHTML; var str =""; str+= '<span class="trclass" id="sortTr' + num + '">'+ '<select id="selectid' + num +'" name="expert.expertBaseSortList[' +num+ '].expertBaseId">'+option+'</select>'+string+ '<br></span>'; num++; document.getElementById("sortDiv1").innerHTML =document.getElementById("sortDiv1").innerHTML+str; } /** 移除 **/ function removeSort(id) { $("#sortTr"+id).remove(); }
思路:首先讲select 给展示出来,然后利用js代码,把select的所有option拷贝下来,再在js下面拼写一个select,将复制好的option放进去.最后赋值给写好的div
解决问题:如果不拷贝上面的option代码,用struts2的标签直接写S:select 代码会出现不能识别S:select标签