熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Javascript >> 正文

js checkbox(復選框) 使用集錦

2022-06-13   來源: Javascript 
function selectAll() //全選
{
var objs = documentgetElementsByName(twId);
var i;
for(i = ; i < objslength; i++)
{
if(objs[i]type == checkbox)
{
objs[i]checked = true;
}
}
}
function unselect() //反選
{
var objs = documentgetElementsByName(twId);
var i;
for(i=;i<objslength;i++)
{
if(objs[i]type==checkbox)
{
if(objs[i]checked == true)
{
objs[i]checked =false;
}
else
{
objs[i]checked =true;
}
}
}
}
function idArray() //得到批量處理的twId
{
var objs = windowdocumentgetElementsByName(twId);
var i;
var idArray = new Array();
var j = ;
for(i=;i<objslength;i++)
{
if(objs[i]type==checkbox)
{
if(objs[i]checked == true)
{
idArray[j] = objs[i]value;
j = j + ;
}
}
}
return idArray;
}
function evArray() //得到批量處理的city
{
var objs = windowdocumentgetElementsByName(twId);
var evObj = windowdocumentgetElementsByName(cityStr);
var i;
var evArray = new Array();
var j = ;
for(i=;i<objslength;i++)
{
if(objs[i]type==checkbox)
{
if(objs[i]checked == true)
{
evArray[j] = evObj[i]value;
j = j + ;
}
}
}
return evArray;
}
function selectUser()  //把選擇到的值寫到文本框
{
 var userIds = new Array();
userIds = idArray();
  var userIdString = userIdsjoin();  //數組字符串化
   documentgetElementById(member)value=userIdString;
}

From:http://tw.wingwit.com/Article/program/Java/Javascript/201401/30274.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.