转发:html:select标签用法
?
html:select标签用法</html:select>?
代码解释:
<html:select property="personnelId">?:
该部分代码最终返回的值存储在personnelId变量中;
<html:option value="">请选择</html:option>?
默认选项,值为空,为了满足用户不想选择任何选项的需求;
<html:options collection="personList" property="personId" labelProperty = "personName"/>?:
<html:options>标签会自动根据参数产生多个<option>。其中,collection属性指的是待迭代的集合变量,property设定的是该<option>的value,labelProperty设定的是页面看到的内容。
注:personList必须是Collection类型的,而且封装的是一个包含personId,personName属性的对象。?
?
动态用法二:
有时候用标签的限制太多就用下面这个:
<SELECT name="deid">
<logic:present name="departarray1">
<logic:iterate id="depart" name="departarray1">?
<option value="<bean:write name="depart" property="deId"/>">?
<bean:write name="depart" property="deName"/>?
</option>?
</logic:iterate>
</logic:present>
</SELECT>
?
代码解释:
<logic:present name="departarray1">?:
判断是否存在departarray1对象,如果存在的话,就执行嵌套标签之中的内容,如果不存在就跳过。
<logic:iterate id="depart" name="departarray1">?:
从departarray1集合对象中取出一个对象,并存入对象变量depart中。注:此处的departarray1必须是一个集合类型变量。depart相当于一个局部变量,是用来存储每次取出来的对象的。
<option value="<bean:write name="depart" property="deId"/>">?:
每一个<option>元素选项的value都是<bean:write name="depart" property="deId"/>,含义是depart对象的deID属性值。
<bean:write name="depart" property="deName"/>?:
这是每一个<option>元素在浏览器上的显示,道标depart对象的deName属性值。
你可以在页面里面定义一个变量,然后动态改变这个变量,在函数里面判断这个变量的值后,再设置selected,如:?
form1.myselected.options[i].selected = true
<script>?
var dymanicValue = 'yourDymanicValue';?
function initSel() {?
var oSel = document.getElementById('sel');?
for (var i = 0; i < oSel.length; i++) {?
if (dymanicValue == oSel[i].value) {?
oSel[i].selected = true;?
break;?
}?
}?
}?
window.onload = initSel;?
</script>?
<select id='sel'></select>
- ??????????????????????????? selectObj.options[i].selected =?????????? } ??
- ????? }?????????????????? ??
- } ??
- ??????????????????????????? selectObj.options[i].text = itemText; ??
- ?????????????????????? } ??
- ????? }??? ??
- ????? ??
- } ??
- ??
- {?? ??
- ?????????? selectObj.options.add(varItem); ??
- ????????????
- ??????????????????????????? selectObj.remove(i); ??
- ?????????????????????? } ??
- ????? }????? ??
- } ??
- ??
- ??
- ??
- (} ??
- ??
- ??
- ????? selectObj.options.length = 0; ??
- } ??
- ??
- myselect.name =?myselect.onchange =?} ??
- itemText[0] =?itemValue[1] =??? myselect.options[i] =?myselect.options[0].selected =?document.documentElement.appendChild(myselect); ??
- ??
- } ??
- ??
- ?? HSSelectItem(type,2); ??
- }?? HSInsertItem(type,?? HSDeleteItem(type,4); ??
- }?? HSCurText(type); ??
- }?? HSClear(type); ??
- }?? HSCreate(); ??
- }????????????? ??
- }??
HTML代码: