【发布时间】:2014-03-18 05:33:42
【问题描述】:
如果列为空,我这里有禁用复选框。我有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>
【问题讨论】:
-
旁注:这个
id="checkbox[]"不应该有括号;只有name="checkbox[]" -
@Fred-ii- 好的,谢谢。
-
不客气。另外,这条线
<?php <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="' . $row['id'] . '"'.($row['pr'] == ""?"disabled ":"").' style="cursor:pointer;" class="checkbox"></td> ?>是不正确的。您需要回显<?php ... ?>中的内容,这将引发错误。 -
@Fred-ii- 是的,我附和它,我只是把它剪短了。
-
@Fred-ii- 请帮帮我?