- //selectall與checkin兩個函數實現全選
- function selectall() {
- var value = $("#CheckboxAll").attr("checked");
- var chk = $("[name='chkInviteCode']");
- chk.attr("checked", value);
- }
- function checkin() {
- var chk = $("[name='chkInviteCode']");
- if (chk.length != 0) {
- var i = 0;
- str = "";
- $('[name="chkInviteCode"]').each(function () {
- if ($(this).attr("checked") == true) {
- if (i > 0) {
- str += ",";
- }
- str += $(this).val();
- i++;
- }
- });
- $("#CodeId").val(str.substr(0, str.length - 1));
- if (chk.length == i) {
- $("#CheckboxAll").attr("checked", "true");
- }
- else {
- $("#CheckboxAll").removeAttr("checked");
- }
- }
- else {
- alert("未選擇!");
- $("#CheckboxAll").removeAttr("checked");
- }
- }
- /************************************/
- <web:TextBox ID="CodeId" Field="CodeId" runat="server" Text="" Width="300" ReadOnly="True" /> //標記ID
- <th><input id="CheckboxAll" type="checkbox" value="all" onclick="selectall();checkin();" />全選</th> //全選複選框
- /************************************/
- <input name="chkInviteCode" id="Checkbox<%# Eval("InviteCodeID")%>" type="checkbox" onclick="checkin();" value='<%# Eval("InviteCodeID")%>'/> //調用checkin函數