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>
																&nbsp;
																<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>



你可能感兴趣的:(移除option,js添加)