如果为空记录,则禁用复选

时间:2014-03-18 05:33:42

标签: php jquery checkbox

如果列为空,我在此处禁用复选框。我有pr列,如果该列为空,则会禁用复选框。我也有下拉列表,如果我选择它隐藏另一个链接。

但真正的问题是,当我选择添加按钮时,只允许检查空列,或者禁用具有值的列。如果我选择删除/编辑所有具有值的列,则只应检查。

请帮忙吗?

代码:

<script type="text/javascript" language="javascript">  
function setCheckboxes3(act) {
    $('.checkbox').not(':disabled').prop('checked', act == 1 ? true : false);
}
</script>
<script>
jQuery(function ($) {
    $('a.button.edit, a.button.remove, a.button.add').click(function () {
        if ($('input[name="checkbox[]"]:checked').length == 0) {
            return;
        }

        if ($(this).hasClass('edit')) {
            if (!confirm('Edit this Record(s)?')) {
                return
            }
        } else /*if ($(this).hasClass('remove')) */{
            if (!confirm('WARNING !!! All Purchase Order that included in this Record(s) will be deleted.')) {
                return
            }
        }

        var frm = document.myform;
        if ($(this).hasClass('edit')) {
            frm.action = 'editpr.php';
        }
        if ($(this).hasClass('add')) {
            frm.action = 'addmulpr.php';
        }
        if ($(this).hasClass('remove')) {
                if (!confirm('Are you sure want to continue?')) {
                return
            }
        }
        frm.submit();
    });
});
</script>

<select id="button1">
<option value="add" selected="selected">Add</option>
<option value="edit">Edit</option>
<option value="delete">Delete</option>
</select>
<?php
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="' . $row['id'] . '"'.($row['pr'] == ""?"disabled ":"").' style="cursor:pointer;" class="checkbox"></td> ?>

  <a class="button add buttons" style="cursor:pointer;"><span><b>Add Purchase Request</b></span></a>
  <a id="edit" class="button edit buttons" style="cursor:pointer;"><span><b>Edit Purchase Request</b></span></a>
  <a id="remove"class="button remove buttons" style="cursor:pointer;" name="remove"><span><b>Remove Purchase Request</b></span></a> 
  <input type='hidden' class='button' name='remove'/>
  <a href="javascript:setCheckboxes3(true);" class="button chkmenu"><span><b>Check All</b></span></a>
  <a href="javascript:setCheckboxes3(false);" class="button chkmenu"><span><b>Uncheck All</b></span></a>
<script>
$('#button1').change(function () {
    var index = $(this).find('option:selected').index();
    $('a.buttons').eq(index).show().siblings('a.buttons').hide();
}).change();
</script>

1 个答案:

答案 0 :(得分:-1)

请参阅id命名约定.. Limit to jQuery id strings?

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number  of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").