js添加,移除option



function addOptions(){
var dataType= document.getElementById("dataType").value;
var periodBeginTime= document.getElementById("periodBeginTime").value;
var periodEndTime= document.getElementById("periodEndTime").value;
if(dataType==1){
op="周末:"+periodBeginTime+"-"+periodEndTime;
}else{
op="节假日:"+periodBeginTime+"-"+periodEndTime;
}

var opts = document.getElementById("periodList");

var objOption=document.createElement("OPTION");
var valuetemp=dataType-periodBeginTime-periodEndTime;
objOption.value=valuetemp;
objOption.text=op;
opts.add(objOption);

}

function removeOptions(){
var opts = document.getElementById("periodList");
for(var i=opts.length-1;i>=0;i--){
if(opts.options[i].selected==true){
opts.options[i]=null;
}
}
}

<table width="100%">
<tr>
<td width="41%">

<table width="266">
<tr>
<td width="258">
时间类型:
<select name="dataType" id=dataType>
<option value="1" selected="selected">
周末
</option>
<option value="2">
节假日
</option>
</select>
 
<button type="" class="btn2" onclick="addOptions()">
添加
</button>
</td>
</tr>
<tr>
<td>
开始时间:
<input type="text" name="periodBeginTime" size="5" id="periodBeginTime"
maxlength="10" value="" class="input-text" />
(格式00:00)
<br>
结束时间:
<input type="text" name="periodEndTime" size="5" id="periodEndTime"
maxlength="10" value="" class="input-text" />
</td>
</tr>
</table>
</td>
<td width="56%">

<table>
<tr>
<td align="left">
<select size="6" id="periodList" multiple="multiple" >

</select>
</td>
<td>
<table>
<tr>
<td>
<img src="../images/edit.gif" />
编辑
</td>
</tr>
<tr>
<td>
<a href="#" onclick="removeOptions()">
<img src="../images/del.gif" alt="删除用户" />
删除
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值