源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

js multiple全选与取消全选实现代码

  • 时间:2020-10-10 18:59 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:js multiple全选与取消全选实现代码
[u]复制代码[/u] 代码如下:
$("select").change(function(){     var n = $(this).children().length;     var obj;     var i = 1;        $(this).children().each(function(){      if(i == n)      {       alert($(this).text());      }      i++;     });    });
综合以上二法,本人轻易得出了自己想要的效果,如下:
[u]复制代码[/u] 代码如下:
function selectall() {  $("select").children().each(function(){$(this).attr("selected","selected")}) }
分别用到了 children()和$(this).attr("selected","selected") 一个js用法
[u]复制代码[/u] 代码如下:
<!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) 消费者行为与销售心理</option> <option value="004" >(004) 产品策划与市场推广</option> <option value="005" >(005) 品牌定位与广告原理</option> </select> <input type="button" onclick="selectAll()" value="全选"> </form> </body> </html>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部