Hi i have one listbox with some values. i want to select it's value based on a value in array list using JSTL. My code is something like that
<select id='lstType' name="lstType">
<option value="abc" selected="yes">abc</option>
<option value="bcd">bcd</option>
<option value="efg">efg</option>
</select>
and a arraylist having some object of entity class.
class entity{
String str;
}
Now on jsp page i am fetching like this
$("#lstCategory option[value = <c:out value="${entity.str}"/>]").attr("selected", true);
Instead of attr use prop
$('#lstType option[value="${entity.str}"]').prop("selected", "selected");
Edit:
Use above only if you are in jQuery 1.6 if using before version use
$('#lstType option[value="${entity.str}"]').attr("selected", "selected");
尝试使用此声明:
$('#lstType option[value="${entity.str}"]').attr("selected", "selected");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.