下拉列表
下拉列表置空
1. $get("isFinish").length = 0
2.$get("isFinish").options.length = 0 //获得dom对象 将长度置为0 加options或者不加都行
下拉获得 显示值 和 实际值
var isFinsh = $get("isFinish").options[$get("isFinish").selectedIndex].text
var isFinsh = $get("isFinish").options[$get("isFinish").selectedIndex].value
下拉列表 默认值
1.document.getElementById('id').selectedIndex=num //得到dom对象后将属性selectedIndex 设置第几行第几行就是默认值
2.
- function selectValue(sId,value){
- var s = document.getElementById(sId);
- var ops = s.options;
- for(var i=0;i<ops.length; i++){
- var tempValue = ops[i].value;
- if(tempValue == value)
- {
- ops[i].selected = true;
- }
- }
- }
例一 // 本身就有下拉列表 才能添加数据
$get("isFinish").options.length = 0;
var o = document.createElement("option"); o.value = ""; o.text = ""; $get("isFinish").options.add(o); var o = document.createElement("option"); o.value = userNameAll; o.text = "是√"; $get("isFinish").options.add(o); var o = document.createElement("option"); o.value = ""; o.text = "否"; $get("isFinish").options.add(o);
例二
package com.jtv.kmiss.module.kwvfaulttips.manager;
import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import com.jtv.kmiss.module.kwvfaulttips.entity.*;import com.jtv.framework.core.domain.manager.support.BaseSingleEntityManagerSupport;/** * KwVFaultTips管理器类. * <p> * * @version 2013-08-22 * @author zhangjj */public class KwVFaultTipsManager extends BaseSingleEntityManagerSupport<KwVFaultTips> implements IKwVFaultTipsManager { /** * 根据cycleId 得到编组 * * @param map * @return */ public List getGroupId(Map<String, String> map) { List list2 = new ArrayList(); String cycleId = map.get("cycleId"); if (cycleId != null) { List list = this.getDao().retrieveByNamedQuery("getGroupId", "cycleId", cycleId); if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { Map<String, String> map1 = new HashMap<String, String>(); String groupId = (String) (((Object[]) list.get(i))[1]); map1.put("groupId", groupId); list2.add(map1); } } } return list2; }}/* charset:UTF-8 *//***页面加载完加载*/function doAfterInitControl(){ var tnum = $get("cycleId"); gf_addEvent(tnum,"onchange",setGroupId);}/*** 根据车次找组*/function setGroupId(){ var cId = $get("cycleId").value; //车次id //dwr 调用后台方法 得编组 gf_dwrInvoke("kwVFaultTipsManager","getGroupId",{ "cycleId":cId },function(result){ if(result!= undefined && result !=null){ var o = document.createElement("option"); o.value=""; o.text=""; $get("groupId").options.add(o); for(i = 0; i<result.length;i++){ var o = document.createElement("option"); o.value = result[i].groupId; o.text = result[i].groupId; $get("groupId").options.add(o); } } });}