多选+jquery+取值

2010-11-03 17:46:46 by 【6yang】, 175 visits, 收藏 | 返回

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>For select  multiple</title>
</head>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script>
$(function(){
 $("#submit").click (function(){ 
  var arr = [];
  $("select option:selected").each(function(i,n) {
            arr[i]=$(this).text();
        });
  //arr = arr.replace(/,$/,''); 
  $.each(arr, function(i,n){
    $("#selectedText ul").append("<li>"+n+"</li>");
  });
  
 });
})
 
</script>
<style type="text/css">
#pannel ul{
 
}
#pannel li.blank{
 background:#f2f2f2;
}
#pannel li.placeholder{
 background:#f2f2f2;
 border:2px dotted #999;
 height:48px;
 width:118px;
}
#pannel li{
  background:#CCC;
  border:1px solid #999;
  cursor:move;
  margin-bottom:1px;
  color:#333;
  height:50px;
  list-style:none;
  width:120px;
}
</style>

<body>
<div id="pannel">
 <form action="#" method="post">
  <select name="sList" multiple="multiple">
   <option value="select01">select01</option>
   <option value="select02">select02</option>
   <option value="select03">select03</option>
   <option value="select04">select04</option>
   <option value="select05">select05</option>
   <option value="select06">select06</option>
   <option value="select07">select07</option>
   <option value="select08">select08</option>
  </select>
  <a  href="#"  id="submit">提交</a>
 </form>
</div>

<div  id="selectedText"><ul></ul></div>
</body>
</html>

分享到:
share

    图片原图

    loading

    loading