gpt4 book ai didi

javascript - 如何从 Bootstrap 表中获取 td click 事件?

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

我正在尝试将事件归因于我的 bootstrap 表的不同列的单元格。

问题是:虽然我已经为每一列设置了一个类,但是归于这个类的事件并没有被触发。我仍然尝试为单元格中添加的每个 div 设置一个类,但它的事件也没有被触发。

那么,如何使用 bootstrab 表获取 td 事件?

最佳答案

这里是bootstap表的td点击事件的完整代码

$(document).ready(function(){
$('table td').click(function(){
alert($(this).html());
});

});
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">

<p>Click on the td below</p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>

</body>
</html>

关于javascript - 如何从 Bootstrap 表中获取 td click 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31617328/

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