select 操作选中添加、删除操作Javascript

//添加选中项
function addItem()
{
var myMember = document.getElementById("myMember");
var otherMember = document.getElementById("otherMember");
for (var i=0;i<myMember.options.length;i++){ if (myMember.options[i].selected == true){
if(!isExitItem(myMember.options[i].value)){
$("#otherMember").append("<option value='" + myMember.options[i].value + "'>" +myMember.options[i].text + "</option");
}
}
}
}
//添加全部项
function addAll()
{
var myMember = document.getElementById("myMember");
var otherMember = document.getElementById("otherMember");
for (var i=0;i<myMember.options.length;i++){
if(!isExitItem(myMember.options[i].value)){
$("#otherMember").append("<option value='" + myMember.options[i].value + "'>" +myMember.options[i].text + "</option");
}
}
}
//删除全部项
function removeAll()
{
var otherMember = document.getElementById("otherMember");
var length = otherMember.options.length;
for(var i=length-1;i>=0;i--){
otherMember.options.remove(i);
}
}
//判断项是否存在
function isExitItem(val)
{
var flag=false;
var otherMember = document.getElementById("otherMember");
for (var i=0;i<otherMember.options.length;i++){
if (otherMember.options[i].value == val){
flag=true;
break;
}
}
return flag;
}
//删除选中项
function removeItem()
{
var otherMember = document.getElementById("otherMember");
for (var i=0;i<otherMember.options.length;i++){
if (otherMember.options[i].selected == true){
$(otherMember.options[i]).remove();
}
}
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

上一篇:Json 简记


下一篇:Pwn with File结构体之利用 vtable 进行 ROP