With jquery more, forget the original JS is how to write, but also need to consolidate.
Requirements: JSP echo a select Drop-down box. Select the specified value.
The user clicks Modify the Select to make an existing value echo. There are two ways to solve this problem
One, JS get the user's Swig_dmselect value, in this case, from the action of the JS get all option, and then traverse to judge.
<script type= "Text/javascript" >
<%
String swjg_dmselect = (String) session.getattribute ("Swjg_ Dmselect "); Gets the value
%>
var obj = document.getelementsbytagname ("option")
//traversal option for
(Var i=0;i< obj.length;i++) {
if (obj[i].value== ' <%=swjg_dmSelect%> ') {
obj[i].selected=true; Equality is selected
}
}
</script>
You can set the Id,id value value for option
<script type= "Text/javascript" >
<%
String swjg_dmselect = (String) session.getattribute ("Swjg_ Dmselect "); Gets
The value%>
document.getElementById ("<%=swjg_dmSelect%>"). Selected=true;
</script>
In the absence of jquery, the following places have Jam 1, how to write Java code 2 in JS, how to traverse array 3, how to select the specified option