function selectall()
{
$("select").children().each(function(){$(this).attr("selected","selected")})
}
分別用到了 children()和$(this).attr("selected","selected")
一個(gè)js用法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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>
</head>
<body>
<select id="CourseList" name="CourseList" multiple="multiple" size="20" style="width:230px;">
<option value="003" >(003) 消費(fèi)者行為與銷售心理</option>
<option value="004" >(004) 產(chǎn)品策劃與市場推廣</option>
<option value="005" >(005) 品牌定位與廣告原理</option>
</select>
<input type="button" onclick="selectAll()" value="全選">
</form>
</body>
</html> |