今天在做一個頁面的時候,遇到一個問題,添加和更新使用同一個頁面,當添加的時候,select可以正常使用,如果是更新,那么要求select的值是指定的,并且不可使用,保存時,該控件的值可以正常保存,大家知道select控件沒有readonly屬性,但是我們還需要用到該功能,該如何實現呢?
上網搜索了一下,發現一種不錯的方法,貢獻給大家,代碼如下:
<select name="projInveSour.phaseType"
<c:if test='${method eq "update"}'> onbeforeactivate="return false" onfocus="this.blur()" onmouseover="this.setCapture()" onmouseout="this.releaseCapture()" </c:if>>
<option value="">全部</option>
<option value="立項" <c:if test='${projInveSourForm.projInveSour.phaseType eq "立項"}'>selected</c:if>>立項</option>
<option value="初設" <c:if test='${projInveSourForm.projInveSour.phaseType eq "初設"}'>selected</c:if>>初設</option>
</select>
紅色部分為關鍵代碼,大家參考一下,呵呵