js頁面迴圈input,checked賦值
var str = document.getElementsByName("orgPer");
var objarray = str.length;
var namelists = ""; //名字
var idlist = ""; //id
document.getElementById("xzry_textarea").type="hidden";
for(i = 0; i < objarray; i++) {
if(str[i].checked) {
namelists += str[i].value + ",";
idlist += str[i].id + ",";
if(document.getElementById("yx_"+str[i].id)){
continue;
}
var selecteddiv=document.getElementById("selected_id");//人員圖示
var imgdiv=document.createElement("div");
imgdiv.className="image";
imgdiv.style.border="1px solid #25a5ff";
imgdiv.style.float="left";
imgdiv.innerText=str[i].value;
imgdiv.id = "yx_"+str[i].id;
imgdiv.style.marginLeft="2%";
imgdiv.style.marginTop="2%";
imgdiv.style.textAlign="center";
imgdiv.style.marginBottom="2%";
imgdiv.style.lineHeight="24px";
imgdiv.style.color="#25a5ff";
imgdiv.style.padding="1px";
imgdiv.style.paddingLeft="3px";
imgdiv.style.paddingRight="3px";
selecteddiv.appendChild(imgdiv);
}else{
var temp = document.getElementById("yx_"+str[i].id)
if(temp){
var selecteddiv=document.getElementById("selected_id");
selecteddiv.removeChild(temp);
}
}
}
document.getElementById("xzry_textarea").value = namelists;
document.getElementById("xzry_input").value = idlist;
}