0

清楚地提出我的问题

使用 sql server 2008 Enterprise 作为数据库服务器检查我的代码

表视图

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<form method="post" name="form" id="checkForm" action="update.php">

<?php
$aksi="aksi_view.php";
switch($_GET[act]){
  // Tampil User
  default:

    echo "
    <table>
    <tr><th>Ap</th><th>Ccl</th><th>No</th><th>Budg</th><th>Dept</th><th>ItemID</th><th>Item Name</th><th>Qnty</th><th>UOM</th><th>Curr.</th><th>Rate</th><th>Unit Price</th>
    <th>Total</th><th>Total-IDR</th></tr>";

    $p      = new Paging;
    $batas  = 20;
    $posisi = $p->cariPosisi($batas);

    $counter = 1;

    $sql = "SELECT TOP 20 BudgetCategoryID,DeptAbbr, BudgetCategoryAbbr, ItemID, Status,
                            QntyDept, Qnty, CurrencyID, UnitPrice, ExchangeRateIDR, Remark,Proposal,
                            DeptApprovalRemark, M2ApprovalBy, M2ApprovalRemark, ItemName, PurchaseUOMName,
                            DecimalInQnty,(Qnty*UnitPrice) as Total, TotalIDR, CompanyDeptStock, CompanyDeptID, OutstandingNPBB
                            FROM vwBudgetApproval
                            WHERE (M2ApprovalBy IS NOT NULL OR (M2ApprovalBy IS NULL AND  Status =1)) AND 
                            CompletedInd = 1 AND DeptApprovalBy IS NOT NULL 
                            ORDER BY BudgetCategoryID, ItemID";
    $tampil = mssql_query($sql) ;

$no = $posisi+1;

while($r=mssql_fetch_array($tampil)){
  // echo"$no=2 '-'"; 
   //echo"$r[ItemID]";
      $ExchangeRateIDR = number_format($r['ExchangeRateIDR'],2,',','.');
    $unitprice = number_format($r['UnitPrice'],2,',','.'); 
    $total = number_format($r['Total'],2,',','.');
    $totalidr = number_format($r['TotalIDR'],2,',','.');


    $warnaGenap = "#66CCFF";   // warna abu-abu
    $warnaGanjil = "#FFFFFF";  // warna putih

if ($counter % 2 == 0) $warna = $warnaGenap;
else $warna = $warnaGanjil;


echo "<tr bgcolor='".$warna."'>            


 <td><input type= 'checkbox' name='approve".$no."' id='approve'   value='".$r['ItemID']."' onclick='onClickFn()'></td>
                    <td><input type= 'checkbox' name='cancel".$no."' id='cancel'   value='".$r['ItemID']."' onclick='onClickFn()'></td> 
                    <td>$no</td>
                    <td>$r[BudgetCategoryAbbr]</td>
                    <td>$r[DeptAbbr]</td>
                    <td>$r[ItemID]</td>
                    <td>$r[ItemName]</td>
                    <td>$r[Qnty]</td>
                    <td>$r[PurchaseUOMName]</td>
                    <td>$r[CurrencyID]</td>
                    <td>$r[ExchangeRateIDR]</td>
                    <td>$unitprice </td>
                    <td>$total</td>
                    <td>Rp $totalidr</td>";             
          $no++;
          $counter++;

        }
    echo "</table>";
?>

页面的显示

图片

现在我希望用户在选中一个复选框时另一个复选框禁用我使用 java 脚本的功能。这是我的代码

<script type="text/javascript">
function onClickFn(){
$("approve").click(function(){
    if ($(this).prop("checked"))
    {
        $("cancel").prop("checked",false);
    }
});

$("cancel").click(function(){
    if ($(this).prop("checked"))
    {
        $("approve").prop("checked",false);
    }
})
};
</script>

但该功能不起作用。

4

3 回答 3

2
1. First of all you have given same id to all <TD>.
2. You haven't used proper id reference in your javascript.
3. Use radio button instead.
于 2013-03-04T06:56:17.713 回答
1

jQuery:

$('table').on('click', 'input:checkbox', function() {
    $(this)
    .parents('tr')
    .find('input:checkbox:not(:checked)')
    .attr('disabled', $(this).is(':checked'));
});

http://jsfiddle.net/samliew/ERZge/

但是,您确实应该使用单选按钮,除非您当然希望用户能够取消选中复选框。

于 2013-03-04T07:03:41.730 回答
0

你为什么不只使用单选按钮?这似乎是一个更好的选择。此外,如果您希望禁用单选按钮,这就是 jQuery 的样子: jQuery("input:radio").attr('disabled',true);

于 2013-03-04T06:56:05.953 回答