jquery顯示隱藏input對象

字號:


    1 所屬部門選擇其他時 顯示一個輸入框進(jìn)行填寫
    
    #html
    <select id='deptid' name='deptid' onchange='deptChange()'>
     <c:forEach var="item" items="${deptidList}" varStatus="status">
     <option value='${item.value}'>&nbsp;${item.name}&nbsp;</option>
     </c:forEach>
    </select>
    <!-- 類型為其他時 需要填寫其它部門 -->
    <input id='otherDept' name='otherDept' type="text" maxlength='50' style='display:none;'/>
    //js
    // 根據(jù)切換是否顯示其他部門輸入框
     function deptChange(){
     var deptid = $('#deptid').val();
     // alert('type:'+hytpye);
     if(deptid=='other'){
      $('#otherDept').show();
     }else{
      $('#otherDept').hide();
     }
     }