HTML代码:
<div align="left">
<div style="float:left">
<select name="select1" size="20" id="allTimeLimitmr" multiple="multiple" style="height: auto;width: auto;">
<option value="null" disabled="disabled" > <fmt:message key="setting.timelimitmr"/> </option>\
<c:if test="${tlmr!=null}">
<c:forEach items="${tlmr}" var="TimeLimitmr" >
<option value='${TimeLimitmr.match_rule_id}' >${TimeLimitmr.match_rule_name}</option>
</c:forEach>
</c:if>
</select>
</div>
<div style="float:left; margin-top:100px;margin-left: 2px">
<input name="button" type="button" onclick="addTache();" value="<fmt:message key="button.add" />" /><br>
<input name="button3" type="button" onclick="removeTache();" value="<fmt:message key="button.delete"/>" /><br>
</div>
<div style="float:left">
<select name="select" size="20" id="select" multiple="multiple" style="height: auto;width: auto;">
<option value="null" disabled="disabled" > <fmt:message key="setting.timelimitmr.have"/> </option>
<c:if test="${tlmr!=null}">
<c:forEach items="${isselect}" var="istimeLimitmr" >
<option value='${istimeLimitmr.match_rule_id}' >${istimeLimitmr.match_rule_name}</option>
</c:forEach>
</c:if>
</select>
</div>
</div>
JAVASCRIPT代码:
function addTache(){
var len= document.getElementById("allTimeLimitmr").length;
for(var i=0;i<len;i++){
var option = document.getElementById("allTimeLimitmr").options[i];
if(option.selected == true && option.index!=0){
var newoption = document.createElement('option');
newoption.value = option.value;
newoption.text = option.text;
document.getElementById("select").add(newoption);
}
}
}
function removeTache(){
var len= document.getElementById("select").length;
for(var i=0;i<len;i++){
var option = document.getElementById("select").options[i];
if(option.selected == true && option.index!=0 ){
var tempoption = document.getElementById("select").options[i];
document.getElementById("select").options[i].removeNode(true);
}
}
}
function submitTache(){
var len = document.getElementById("select").length;
var formobject = document.getElementById("alarmRuleForm");
for(var i=0;i<len;i++){
var option = document.getElementById("select").options[i];
if(option.index!=0 ){
var actiontype= "0";
var input = document.createElement("<input type='hidden' name='timelimitmr' />");
input.value=option.value;
formobject.insertAdjacentElement("beforeEnd",input);
}
}
formobject.submit();
}
</script>