gpt4 book ai didi

javascript - 修复了表中的左列

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

我想问一下,我有如下代码:

// requires jquery library
jQuery(document).ready(function() {
jQuery(".main-table").clone(true).appendTo('#table-scroll').addClass('clone');
});
.table-scroll {
position: relative;
max-width: 600px;
margin: auto;
overflow: hidden;
border: 1px solid #000;
}

.table-wrap {
width: 100%;
overflow: auto;
}

.table-scroll table {
width: 100%;
margin: auto;
border-collapse: separate;
border-spacing: 0;
}

.table-scroll th,
.table-scroll td {
padding: 5px 10px;
border: 1px solid #000;
background: #fff;
white-space: nowrap;
vertical-align: top;
}

.table-scroll thead,
.table-scroll tfoot {
background: #f9f9f9;
}

.clone {
position: absolute;
top: 0;
left: 0;
pointer-events: none;
}

.clone th,
.clone td {
visibility: hidden
}

.clone td,
.clone th {
border-color: transparent
}

.clone tbody th {
visibility: visible;
color: red;
}

.clone .fixed-side {
border: 1px solid #000;
background: #eee;
visibility: visible;
}

.clone thead,
.clone tfoot {
background: transparent;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="table-scroll" class="table-scroll">
<div class="table-wrap">
<table class="main-table">
<thead>
<tr>
<th class="fixed-side" scope="col">&nbsp;</th>
<th class="fixed-side">Left Column</th>
<th scope="col">Header 2</th>
<th scope="col">Header 3</th>
<th scope="col">Header 4</th>
<th scope="col">Header 5</th>
</tr>
</thead>
<tbody>
<tr>
<th class="fixed-side"><a href="javascript:void(0);" onclick="alert('asd')">Test</a></th>
<th class="fixed-side">Left Column</th>
<td>Cell content<br> test
</td>
<td>Cell content longer</td>
<td>Cell content</td>
<td>Cell content</td>
</tr>
<tr>
<th class="fixed-side">Left Column</th>
<th class="fixed-side">Left Column</th>
<td>Cell content</td>
<td>Cell content longer</td>
<td>Cell content</td>
<td>Cell content</td>
</tr>
</tbody>
<tfoot>

</tfoot>
</table>
</div>
</div>

我的问题是,当我创建的表格滚动时,我制作的警报功能无法点击/不起作用。我想要做的是当我按下 test link 我创建的警报可以工作

谁能给我一个解决方案,我应该更改哪些内容才能让我创建的代码正常工作?

最佳答案

您正在使用 clone 克隆元素有pointer-events:none的类(class)这会阻止您点击,因此只需将其删除即可。

阅读更多关于 pointer-events 的信息

// requires jquery library
jQuery(document).ready(function() {
jQuery(".main-table").clone(true).appendTo('#table-scroll').addClass('clone');
});
.table-scroll {
position: relative;
max-width: 600px;
margin: auto;
overflow: hidden;
border: 1px solid #000;
}

.table-wrap {
width: 100%;
overflow: auto;
}

.table-scroll table {
width: 100%;
margin: auto;
border-collapse: separate;
border-spacing: 0;
}

.table-scroll th,
.table-scroll td {
padding: 5px 10px;
border: 1px solid #000;
background: #fff;
white-space: nowrap;
vertical-align: top;
}

.table-scroll thead,
.table-scroll tfoot {
background: #f9f9f9;
}

.clone {
position: absolute;
top: 0;
left: 0;
}

.clone th,
.clone td {
visibility: hidden
}

.clone td,
.clone th {
border-color: transparent
}

.clone tbody th {
visibility: visible;
color: red;
}

.clone .fixed-side {
border: 1px solid #000;
background: #eee;
visibility: visible;
}

.clone thead,
.clone tfoot {
background: transparent;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="table-scroll" class="table-scroll">
<div class="table-wrap">
<table class="main-table">
<thead>
<tr>
<th class="fixed-side" scope="col">&nbsp;</th>
<th class="fixed-side">Left Column</th>
<th scope="col">Header 2</th>
<th scope="col">Header 3</th>
<th scope="col">Header 4</th>
<th scope="col">Header 5</th>
</tr>
</thead>
<tbody>
<tr>
<th class="fixed-side"><a href="javascript:void(0);" onclick="alert('asd')">Test</a></th>
<th class="fixed-side">Left Column</th>
<td>Cell content<br> test
</td>
<td>Cell content longer</td>
<td>Cell content</td>
<td>Cell content</td>
</tr>
<tr>
<th class="fixed-side">Left Column</th>
<th class="fixed-side">Left Column</th>
<td>Cell content</td>
<td>Cell content longer</td>
<td>Cell content</td>
<td>Cell content</td>
</tr>
</tbody>
<tfoot>

</tfoot>
</table>
</div>
</div>

关于javascript - 修复了表中的左列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47767658/

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