Copy Code code as follows:
$ ("select"). Change (function () {
var n = $ (this). Children (). length;
var obj;
var i = 1;
$ (this). Children (). each (function () {
if (i = = N)
{
Alert ($ (this). text ());
}
i++;
});
});
Combined with the above two methods, I easily get the effect I want, as follows:
Copy Code code as follows:
function SelectAll ()
{
$ ("select"). Children (). each (function () {$ (this). attr ("Selected", "Selected")})
}
Children () and $ (this) are used respectively. attr ("Selected", "Selected")
A JS usage
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<script type= "Text/javascript" >
<!--
function SelectAll ()
{
var Opts=document.getelementbyid ("Courselist");
for (Var i=0;i<opts.length;i++)
{
Opts[i].selected=true;
}
}
-->
</script>
<body>
<select id= "courselist" name= "courselist" multiple= "multiple" size= "style=" "width:230px"; >
<option value= "003" > (003) Consumer behavior and sales psychology </option>
<option value= "004" > (004) Product planning and market promotion </option>
<option value= "005" > (005) Brand positioning and advertising principles </option>
</select>
<input type= "button" onclick= "SelectAll ()" value= "Select All" >
</form>
</body>