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].
相关文档:
scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetL ......
<html>
<body>
<script type="text/JScript">
for (i=0; i<10000; i++) { // this loop enforces the effect
var model = new Object();
var element = document.createElement("<br>");
model.myElement = ......
http://xiayuanfeng.javaeye.com/blog/(原文)
什么是函数(Function)
function sum(a,b){
return a+b;
}
其实通俗的说就是一个有名称的代码段,方便重用。
要注意的是:
1.Javascript 的函数语法,因为Javascript本身就是区分大小写的,所以function不能写作Function或 ......
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 ......