JavaScript控制checkbox全选,以及获取checkbox文本
这里考虑的是.net服务器控件checkbox或checkboxList;
假设页面如下,chkDepart是部门,chkPeople是所属部门的人员
<div style="text-align: center" mce_style="text-align: center" width="95%" class="tab">
<asp:DataList ID="DataList1" runat="server" Width="100%" RepeatDirection="vertical"
OnItemDataBound="DataList1_ItemDataBound" GridLines="Horizontal" RepeatLayout="table">
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="chkDepart" runat="server" Text="" /></td>
</tr>
<tr>
<td style="text-align: left" mce_style="text-align: left" nowrap="nowrap">
<asp:CheckBoxList RepeatDirection="horizontal" RepeatLayout="table" nowrap="nowrap"
ID="cblPeople" runat="server" /></td>
</tr>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" />
</asp:DataList>
</div>
设置全选或全不选
function onDepartSelect(chk,iid)
{
var p=chk;var v=0;
for(var fld=0;fld<document.form1.elements.length;fld++)
{
var elt=document.form1.elements[fld];
if(elt.type=="checkbox" && elt.id.indexOf(iid)>-1)
{
elt.checked=chk.checked;
}
}
}
获取所选checkbox的Text
由于checkbox生产的html代码是用label来显示其文本,并且以"for"属性的值和checkbox的id对应,因此可以用
var lbs=document.getElementsByTagName获取所有label,再根据lbs[i].
相关文档:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>JS调用现成Word模板完成打印</title>
<script type="text/javascript">
//转换word的函数
function ......
// 下拉列表类
// PubEdition: Version 1.0.0.0
// ModifyDate: 2009-12-09 9:30:00
// FinishDate: 2009-12-09 9:30:00
// AuthorName: binbin( Mail:pl45@163.com / Tel:13893302154 )
var droplistswap=function(){};
droplistswap.prototype.originalElement=new Array();
// droplistswap.prototype.hidedropl ......
前台页面为 子页面为一个按钮:
<form id="form1" runat="server">
<div>
<asp:Button runat="server" ID="Bt_Add" Text="添加" Width="80px" Height="20px" OnClick="Bt_Add_Click" />
</div>
  ......
自定义控件中的页面代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="wcontrol.ascx.cs" Inherits="wcontrol" %>
<script type ="text/javascript">
function PopupCalendar(InstanceName)
{
///Global Tag
this.instanceName=InstanceName;
///Properties
this.separator="-"
t ......
Several programming languages implement a sprintf function, to output a formatted string. It originated from the C programming language, printf function. Its a string manipulation function.
This is limited sprintf Javascript implementation. Function returns a string formatted by the usual printf co ......