jsp 输入框同时支持手工输入(模糊搜索)和下拉选

<tr>

  <th width="130px"><em>*</em></th>

  <td width="260px">

    <input type="text" class="text02" id="userOption" list="userlist">

    <datalist id="userlist">

      <c:forEach items="${userlist}" var="userVo">

        <option value="${userVo.userid}" aa="${userVo.num}">${userVo.userid}</option>

      </c:forEach>

    </datalist>  

  </td>

</tr>

 

取值:

var user_options= $("#userlist").children();

for(var i=0;i<user_options.length;i++){

  if(user_options.eq(i).val().trim() == $("#userOption").val().trim()){

    var user_id = user_options.eq(i).val();

    var user_num =user_options.eq(i).attr("aa");

    break;

  }

}

posted on 2019-12-06 10:58  24ming  阅读(1794)  评论(0编辑  收藏  举报