关于页面两个列表的数据传输的js算法

页面设计如下:
        <td>
            <select id="availableRoles" size="10" multiple="multiple" style="width: 150px;">
             <option></option>
            </select>
       </td>
       <td align="center">
            <a href="javascript:secure.addRole()" class="button" style="width: 60px;">Add &gt;</a>
            <br/>
            <a href="javascript:secure.removeRole()" class="button" style="width: 60px;">&lt; Remove</a>
       </td>
       <td>
            <select id="roles" size="10" multiple="multiple" style="width: 150px;">
             <option></option>
            </select>
       </td>

对应的js如下(这里的js是使用的prototype的js方法)

Security = Class.create();

Security.prototype =
{



addRole: function()
 {
  var availableRolesList = $("availableRoles");
  var rolesList = $("roles");
  this.moveOption(availableRolesList, rolesList);
 },
 
 removeRole: function()
 {
  var availableRolesList = $("availableRoles");
  var rolesList = $("roles");
  this.moveOption(rolesList, availableRolesList);
 },
 
 moveOption: function(source, target)
 {
  var lastInsert = null;
  for (var i = source.options.length - 1; i >= 0; i--)
  {
   if (source.options[i].selected)
   {
    var option = source.removeChild(source.options[i]);
    target.insertBefore(option, lastInsert);
    lastInsert = option;
   }
  }
 },
}

var secure = null;

function initSecurity()
{
 secure = new Security();
 secure.setup();
}

Event.observe(window, "load", initSecurity, false);


posted on 2007-11-13 20:03 刘铮 阅读(419) 评论(0)  编辑  收藏 所属分类: JavaScript


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

留言簿(1)

文章分类(141)

文章档案(147)

搜索

最新评论