Javascript 带有链接的HTML表格行未选中复选框

Javascript 带有链接的HTML表格行未选中复选框,javascript,Javascript,我有一个在PHP中回响的HTML表: echo '<tr class="notfirst" style="cursor:pointer;" onclick="document.location=\'editinvoice.php?seq='.$result["sequence"].'&inv='.$result["invoice_number"].'\'"> <td width="20"><input type="checkb

我有一个在PHP中回响的HTML表:

echo '<tr class="notfirst" style="cursor:pointer;" onclick="document.location=\'editinvoice.php?seq='.$result["sequence"].'&inv='.$result["invoice_number"].'\'">
                <td width="20"><input type="checkbox" name="check'.$counter.'" id="check'.$counter.'" onclick=\'add('.$total.', this);\' /></td>
                <td width="150">'.$result["invoice_number"].'</td>
                <td width="250">'.$company.'</td>
                <td width="100">'.$date.'</td>
                <td width="100">&pound;'.$result["total"].'</td>
                <td width="100">&pound;'.$result["total"].'</td>
            </tr>';
echo'
“.$result[“发票编号”]”
“.$公司。”
“.$日期。”
&英镑$结果[“总计”]。'
&英镑$结果[“总计”]。'
';

因此,当您将鼠标悬停在该行上时,它会突出显示整行,无论您在何处单击该行,它都会打开链接,但当我选中复选框时,它也会打开链接-我想停止此操作,我认为最好将javascriptcode与html标记分开。这样你就可以更好地控制它

请看一下javascript中的。看看
我希望这有帮助

我会使用
event.stopPropagation()


这是一个jQuery版本,因为它更容易实现,但如果必须的话,可以在DOM access中重写它。如果您这样做了,您还需要为IE“我有一个HTML表在PHP中回响”添加
event.cancelBubble=true
——您想在这里讨论一个客户端问题,因此服务器端代码最无趣。发布客户端收到的代码。在这里@CBroe并不真正必要-很清楚将要呈现什么。对于客户端问题,发布服务器端代码仍然很愚蠢。preventDefault不是我要选择的,我希望选中复选框。
$(function() {
  $(".notfirst").on("click",function() {
    location = "editinvoice.php?seq="+$(this).data("seq")+"&inv="+$(this).data("inv");
  });
  $("checkbox[name^=check]).on("click",function(event) {
    event.stopPropagation();
    add($(this).data("total");
  });
});
echo '<tr class="notfirst" style="cursor:pointer;" data-seq="'.$result["sequence"].'" data-inv="'.$result["invoice_number"].'">
  <td width="20"><input type="checkbox" name="check'.$counter.'" id="check'.$counter.'" data-total="'.$total.'" /></td>
            <td width="150">'.$result["invoice_number"].'</td>
            <td width="250">'.$company.'</td>
            <td width="100">'.$date.'</td>
            <td width="100">&pound;'.$result["total"].'</td>
            <td width="100">&pound;'.$result["total"].'</td>
        </tr>';