How to dynamically disable html <select> in

2019-09-09 11:53发布

问题:

I try to use

<select id="_${sec_field}_id" name="${sec_field}" multiple="${multiple}" "${(empty disabled) ? 'disabled' : ' '}" >

To get the <select> options dynamically enabled/disabled

But Eclipse give me the alerts:

Multiple annotations found at this line:
- Element type "select" must be followed by either attribute specifications, ">" or "/>".
- Attribute """ has no value

So is there any solution that we can work out the disable of html <select> in JSTL?

Thanks in advance.

回答1:

Remove those doublequotes around the EL expression which prints the disabled attribute name. Doublequotes should be placed around the attribute value only (the part after =).

<select ... ${empty disabled ? 'disabled' : ''}>

otherwise you end up with

<select ... "">

or

<select ... "disabled">

which are syntactically wrong.