spring MVC:readonly&残

时间:2016-10-12 11:51:26

标签: html spring jsp spring-mvc

我在JSP中有这个代码

<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;

所以网站不是只读的,而是imageFile si readonly

2 个答案:

答案 0 :(得分:1)

在您的示例中,imageFile元素是使用html创建的,而website元素是由通过Spring的form:input标记生成的html创建的。

要生成由input标记form:inputreadonly生成的disabled元素,您必须使用该标记中的相应属性,该属性可能不一定与属性匹配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。 / p>

答案 1 :(得分:-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">应该禁用它