gpt4 book ai didi

javascript - 使用复选框标记要删除的行

转载 作者:行者123 更新时间:2023-11-30 09:57:38 25 4
gpt4 key购买 nike

我有这个收件箱或邮件,我需要使用复选框标记以进行多次删除。问题是,当我单击复选框时,由于标签内的 onclick,它总是转到方法 read()。我想要的只是简单的标记。请看下面的代码:

@foreach ($messages as $message)    
<tr onclick="document.location='{{route('account.message.read', array($message->id))}}'">
<td> <input type="checkbox" name="msg" value="{{$message->id}}"></td>
<td><strong>{{Str::words($message->subject, 5, '...')}}</strong> {{Str::words($message->message, 20, '...')}}</td>
</tr>
@endforeach

现在如何在不进入该方法的情况下标记每一行?顺便说一句,我是新手。

最佳答案

您只需将处理程序附加到checkbox 并使用stopPropagation从冒泡到树上,看下面的例子:

HTML

假设我们有带有 onclick 内联 javascript 的表格行,并且其中有 input:

<table>
<tr onclick="return alert('Hai')">
<td>
<input type="checkbox" />Click Me
</td>
</tr>
<table>

这里是处理程序:

$('input').click(function(e){
// normally if we removed this line of code
// alert will getting called as checkbox is checked/unchecked
// was inside table rows
// but with this propagation, we disabled it
// from bubbling up into tree
e.stopPropagation();
});

DEMO

关于javascript - 使用复选框标记要删除的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33272740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com