select下拉框回显的几种方式

  • Post author:
  • Post category:其他


第一种:

jsp代码:



  1. <


    select




    id


    =


    “csrqnf”




    name


    =


    “csrqnf”




    id


    =


    “selecte”




    class


    =


    “shortselect”




    value


    =


    “${nfResult}”


    >





  2. <


    option




    value


    =


    “”


    >


    —请选择年份–


    </


    option


    >





  3. <


    c:forEach




    items


    =


    “${listYears}”




    var


    =


    “years”




    varStatus


    =


    “vs”


    >





  4. <


    option




    value


    =


    “${years}”


    >


    ${years}


    </


    option


    >





  5. </


    c:forEach


    >





  6. </


    select


    >





  7. <


    script




    type


    =


    “text/javascript”


    >




  8. document.getElementById(“csrqnf”)

    .value


    =


    “${nfResult}”


    ;


  9. document.getElementById(“csrqnf”)[${nfResult}]

    .selected


    =


    true


    ;




  10. </


    script


    >



后台java代码:



  1. request.setAttribute(“nfResult”,”2013″);

网上摘抄:



  1. <!–



  2. 实现select标签回显



  3. –>




  4. 1.

    <


    select




    name


    =


    “curStatus”




    value


    =


    “${curStatus}”


    >





  5. <


    option




    value


    =


    “0”


    >


    -请选择-


    </


    option


    >





  6. <


    option




    value


    =


    “1”




    <


    c:if




    test


    =


    “${‘1’ eq curStatus}”


    >


    selected


    </


    c:if


    >




    >





    </


    option


    >





  7. <


    option




    value


    =


    “2”




    <


    c:if




    test


    =


    “${‘2’ eq curStatus}”


    >


    selected


    </


    c:if


    >




    >





    </


    option


    >





  8. </


    select


    >





  9. 2.

    <


    s:select




    list


    =


    “#{0:’–请选择–‘,1:’处理中’,2:’已完成’}”




    listKey


    =


    “key”




    listValue


    =


    “value”




    name


    =


    “curStatus”




    value


    =


    “%{curStatus}”


    >


    </


    s:select


    >





  10. 3.

    <


    select




    name


    =


    “curStatus”




    value


    =


    “${curStatus}”


    >





  11. <


    option




    value


    =


    “0”


    >


    -请选择-


    </


    option


    >





  12. <


    option




    value


    =


    “1”




    <


    s:if




    test


    =


    “%{curStatus==1}”


    >


    selected


    </


    s:if


    >




    >


    处理中


    </


    option


    >





  13. <


    option




    value


    =


    “2”




    <


    s:if




    test


    =


    “%{curStatus==2}”


    >


    selected


    </


    s:if


    >




    >


    已处理


    </


    option


    >





  14. </


    select


    >