<div class="codetitle"> <span><a style="CURSOR: pointer" data="65226" class="copybut" id="copybut65226" onclick="doCopy('code65226')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code65226"> <br>$("select").change(function(){<br> var n = $(this).children().length;<br> var obj;<br> var i = 1;<br> $(this).children().each(function(){<br> if(i == n)<br> {<br> alert($(this).text());<br> }<br> i++;<br> });<br> });<br> </div> <br>综合以上二法,本人轻易得出了自己想要的效果,如下:<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="56940" class="copybut" id="copybut56940" onclick="doCopy('code56940')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code56940"> <br>function selectall()<br>{<br> $("select").children().each(function(){$(this).attr("selected","selected")})<br>}<br> </div> <br>分别用到了 children()和$(this).attr("selected","selected")<br>一个js用法<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="34914" class="copybut" id="copybut34914" onclick="doCopy('code34914')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code34914"> <br><br><br><br><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <br><script type="text/javascript"><BR><!--<BR>function selectAll()<BR>{<BR> var opts=document.getElementById("CourseList");<BR> for(var i=0;i<opts.length;i++)<BR> {<BR> opts[i].selected=true;<BR> }<BR>}<BR>//--><BR></script><br><br><br><select id="CourseList" name="CourseList" multiple size="20" style="width:230px;"> <br><option value="003">(003) 娑</option></select> </div>