2016-10-12 31 views
0

我有這樣的代碼在JSPSpring MVC的:只讀和殘疾

<form:input path="userBean.company.addressInfo.website" readonly="${activeField}" disabled="${activeField}" style="width:350px" htmlEscape="true"/> 

    <input id="imageFile" type="file" name="${status.expression}" value="${status.value}" onchange="uploadImageAction()" readonly="${activeField}" disabled="${activeField}" /> 

但是當我在瀏覽器中查看源代碼

<input id="userBean.company.addressInfo.website" name="userBean.company.addressInfo.website" style="width:350px" type="text" value="website hidden"/> 


<input id="imageFile" type="file" name="companyLogo" value="" onchange="uploadImageAction()" readonly="" disabled="" />&nbsp;&nbsp; 

這樣的網站是不是隻讀,但鏡像文件SI只讀

回答

-1

在HTML中,disabledreadonly是HTML元素禁用/只讀的屬性,無論該元素在HTML中的值是多少!

http://www.w3schools.com/tags/att_input_disabled.asp

所以<input ... disabled><input ... disabled="true"><input ... disabled="disabled">渲染所有的殘疾人輸入字段,甚至<input ... disabled="false">應當禁用

1

在您的示例中,imageFile元素使用html創建,而website元素由通過Spring的生成的html創建標籤。

爲了通過Spring的form:input標籤readonlydisabled產生的input元素,則必須從該標籤,這可能不完全一致的HTML屬性名稱和值使用相應的屬性。

參考形式TLD文件:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/spring-form-tld.html#spring-form.tld.input

基本上,如果你想使一個form:input標籤readonly,添加屬性readonly與價值true,如果你想讓它disabled,添加屬性稱爲disabled與價值true

<form:input path="userBean.company.addressInfo.website" readonly="true" disabled="true" style="width:350px" htmlEscape="true"/> 

當然你也可以使用一個變量像activeField爲屬性設置的值,就像你在你的例子有,只需確保值是true當你想要的屬性應用。