1、请单击“文件”“新建”以创建新的web源文件。
2、默认情况下,新类型是OK。如果您有其他需要,可以选择页面类型、布局等,然后单击“创建”按钮。
3、创建新网页后,单击“设计”页上的“插入-表单-选择(列表/菜单)”以插入可选择的下拉表单。
4、或者在菜单栏下有一个表单选项图标。将鼠标放在上面显示“选择(列表/菜单)”并单击它,或插入下拉菜单。
5、然后d出接口,您需要输入标记辅助函数的属性。用英文或数字填写身份z。标记是下拉菜单的相应数据标题,如地址、性别等。在此处填写“性别:”然后单击“确定”。
6、d出是否添加表单标签的提示,选择“是”。
7、此时,下拉菜单将插入页面。单击下面的列表值将内容添加到下拉菜单中。
8、跳出列表值界面,并填写项目标签上的下拉菜单选项。例如,我想在这里制作一个性别选择下拉菜单。在这里,填写男性值和项目标签。
9、然后单击加号在下面添加新标签和值,并填写阴性。然后单击“确定”按钮。
10、然后单击界面上箭头指示的小图标,选择一个浏览器,然后单击它以查看浏览器上的预览效果。
11、此时,系统将提示您保存对网页文件的更改。选择“是”保存。
12、然后您可以看到您在浏览器上创建的下拉菜单的外观。单击一次下拉箭头选择,
总结一下关于web上使用下拉框的情况从数据库中获得数据List,将数据放到Request里面使用setAttribute(”AList”,AList)
A中有2个属性(String id,String value)
1.使用JSTL的forEach方式
<select name=”xx” ……..>
<c:forEach items="${AList}" var="p" >
<c:choose>
<c:when test="${xxx == p.id}">
<option value='<c:out value="${p.id}"/>' selected="selected">
<c:out value="${p.value}"/>
</option>
</c:when>
<c:otherwise>
<option value='<c:out value="${p.id}"/>'>
<c:out value="${p.value}"/>
</option>
</c:otherwise>
</c:choose>
<c:forEach>
</select>
2.使用struts的标签
<html:select property=”xxx”>
<html:options collection="AList" labelProperty="value" property="id" />
</html:select>
查一下struts的api文档,可以看到select 中选项有3 taglib可以使用。
第一种直接使用把所有选项写在中间。
<html:option value="0-15">0-15</html:option><html:option value="15-20" >15-20</html:option><html:option value="20-30" >20-30</html:option><html:option value="20 or above">30 or above</html:option>
第二种:把选项放在一个Collection中(这里使用List).在实际项目中,更多的是可能数据来源于db,文件等。这种情况用得比较多。
<html:options collection="AList" property="value" labelProperty="label"/>把option放在list中的过程在Action中作处理//prepare the age selector list.List ageList =new ArrayList()ageList.add(new LabelValueBean("0-15","0-15"))ageList.add(new LabelValueBean("15-20","15-20"))ageList.add(new LabelValueBean("20-30","20-30"))ageList.add(new LabelValueBean("30 or above","30 or above"))request.setAttribute("AList",AList)
这里使用了LabelValueBean,可以不用的,象
<html:options collection="AList" labelProperty="value" property="id" />
只要在AList中填入的bean有value和id属性就可以
第三种,把此list 作为Form 的一个属性.
<html:optionsCollection property="AList" />
在Form 中添加AList 的setter和getter. Form中作如下处理。
//the list can be a form property.
f.setAgeList(AList)
1.从数据库中获得数据,你应该在Action里面取得数据后,将数据放到Request里面
2.数据取出来后放在一个List或Collection或Map里面,我习惯用List
3.从List或其它的容器中取数据应该用<html:options>或<html:optionsCollection>
4.<html:options>和<html:optionsCollection>外层必须用<html:select property="">,所以这个属性你必须在FormBean里定义
5.由于你要用到这些标签,所以你必须定义FormBean
6.从Action取数据,以List为例
List list = xxxxx//从数据库中取得下拉列表中的数据
request.setAttribute("list",list)
在页面显示
<html:form action="xxxx">...<html:select property="xxx"><html:options collection="list" labelProperty="下拉框中显示的内容,一般是name或其它相似属性" property="各选项对应的值,一般是id" /></html:select>...</html:form>
web中的下拉框selenium处理基本的定位option的方式,还提供了Select类来进行 *** 作方式一:
1.定位option选项,进行点击
方式二:
通过Select类实现
from selenium.webdriver.support.select import Select
select = Select(driver.find_element_by_id("selectA")) # 通过select标签生成Select对象
select.select_by_index(index) # 通过索引获取option
select_by_value(value) # 根据option属性 value值来定位
select_by_visible_text(text) # 通过option标签中的显示文本获取
以前在黑马程序员培训后,也会买他们出版的书,这个就是直接从书上看的。现在很多大学都用的他们的教材,我就会没事看看。反正说的挺详细的。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)