zoukankan      html  css  js  c++  java
  • html:option

      注意事项:

       (1):In HTML the <option> tag has no end tag.HTML中<option>标签不需要关闭。In XHTML the <option> tag must be properly closed. 在XHTML中<option>标签必须合理关闭。

           在使用struts1中包含的下拉列表的标签包含:

        <html:select>生成HTML<select>元素

        <html:option>:生成HTML<option>元素

        <html:options>:生成一组HTML<options>元素

        <html:optionsCollection>生成一组HTML<options>元素。

          其中<html:select>生成HTML<select>元素,表示下拉列表框或多选列表。在<html:select>标签中可以包含多个<html:option>,<html:options>,  <html:optionCollections>元素。

        size属性:指定每次在网页上显示的可选项的数目。

        multipe属性:指定是否支持多项选择,如果设置为true,就表示多选列表,支持多项选择。否则只表示下拉列表。只支持单选操作。默认是false。

        property属性:与ActionForm Bean中的某个属性对应,这个属性用来存放用户在列表上选中选项的值。在单项选择的情况下,ActionForm Bean中的对应属性对应该列表上选项的值。在单项选择情况下,

        ActionForm Bean对应属性应该定义为简单类型(不能为数组),在多项选择情况下,ActionForm Bean中的对应属性应该定义为数组类型,以便存放用户选择的多个选项。

      <html:option>

        <html:option value="1">a</html:option>

           使用sturts1标签完成下拉框。基本示例如下:本地使用国产框架Buffalo.

        jsp脚本: 

        <td>
          <html:select property="grapeResult.grapeOptionId" name="grapeForm" styleId="options">
          </html:select>
        </td>

        <script language="JavaScript" src="<%=request.getContextPath()%>/scripts/buffalo.js"></script>

        var buffaloEmpInfo = new Buffalo('<%=request.getContextPath() %>' + '/xmlhttp');
        var END_POINT="<%=request.getContextPath()%>/xmlhttp";        

        function result(reply){
          var returnResult = reply.getResult();
        $("#options").empty();
          if(returnResult.length > 0){
          for(var index = 0 ; index < returnResult.length ; index++){
            $("#options").append("<option value="+returnResult[index].oid +" style='color:"+returnResult[index].color.name+"'>●</option>");
         }
          }else{
            $("#nobutton").attr("disabled", true);
          }
        }

       <html:options>

            使用coolection属性指定存在某个范围中的集合来生成列表项,注意coolection属性指定的集合,该对象的每一个元素为一个Bean。

        例如有如下实体类  

        package com.pojo;

        public class Users {

        private String userName;
        private String userValue;
        public Users(){}
        public Users(String userName,String userValue){
           this.userName=userName;
           this.userValue=userValue;
        }
        public String getUserName() {
           return userName;
        }
        public void setUserName(String userName) {
           this.userName = userName;
        }
        public String getUserValue() {
           return userValue;
        }
        public void setUserValue(String userValue) {
           this.userValue = userValue;
        }

      }

      将实体类实例放入ArrayList列表然后放入reqeust范围内
         Users u1=new Users("1","高中"); 
         Users u2=new Users("2","本科"); 
         Users u3=new Users("3","硕士"); 
         Users u4=new Users("4","博士"); 
         ArrayList array=new ArrayList();
         array.add(u1);
         array.add(u2);
         array.add(u3);
         array.add(u4);
       request.setAttribute("xueli",array);

       使用<html:options>标签生成可选项

      <html:select property="xueli" multiple="true" size="3">
      <html:options 
         collection="xueli"
         property="userName"
         labelProperty="userValue"/>

      </html:select>:

      collection指定存放在request范围内的集合

      property指定<html:option>实际值
      labelProperty指定<html:option>显示到页面上的文本。

      当使用property属性和labelProperty属性时,会根据属性指定的名称调用相应Bean中的getXXX方法来获得属性值。

      生成HTML效果如下

      <option value="1">高中</option>
      <option value="2">本科</option>
      <option value="3">硕士</option>
      <option value="4">博士</option>

      <html:options>
      <html:options collection="collection" labelProperty="displayName" property="value"/>
      其中collection为一个集合,一般是个ArrayList,displayName为前台显示的名称,value为后台实际使用的值.
      例:<html:options collection="arrayList" labelProperty="name" property="id" />

      

  • 相关阅读:
    is_numeric — 检测变量是否为数字或数字字符串
    intval — 获取变量的整数值
    php获取数组最后一个值
    js正則匹配经纬度(经纬度逗号隔开)
    安装netcat(-bash: netcat: command not found)
    提示-bash: telnet: command not found的解决方法
    Laravel中使用Redis
    鏈接Redis報錯`AUTH` failed: ERR Client sent AUTH, but no password is set [tcp://127.0.0.1:6379]
    使用composer遇到的坑
    laravel的ORM模型的find(),findOrFail(),first(),firstOrFail(),get(),list(),toArray()之间的区别
  • 原文地址:https://www.cnblogs.com/it38/p/5035916.html
Copyright © 2011-2022 走看看