Twitter bootstrap 按ID选择引导表行
我需要选择(突出显示)特定的表行(这是Bootstrap 4表)。Twitter bootstrap 按ID选择引导表行,twitter-bootstrap,bootstrap-4,Twitter Bootstrap,Bootstrap 4,我需要选择(突出显示)特定的表行(这是Bootstrap 4表)。 以下是示例代码: <p><a href="javascript:void(0);" onclick="select(3);">Select Row</a></p> <table id="mtable" class="table table-hover b-t"> <thead> <tr>
以下是示例代码:
<p><a href="javascript:void(0);" onclick="select(3);">Select Row</a></p>
<table id="mtable" class="table table-hover b-t">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr id="tr1">
<td>1</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr id="tr2">
<td>2</td>
<td>Otto</td>
<td>@TwBootstrap</td>
<td>123</td>
</tr>
<tr id="tr3">
<td>3</td>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr id="tr4">
<td>4</td>
<td>Larry the Bird</td>
<td>@twitter</td>
<td>abc</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$('#mtable').on('click', 'tbody tr', function(event) {
$(this).addClass('highlight').siblings().removeClass('highlight');
});
function select(rowID){
// here I need to find tr3 and select it.
}
</script>
#
名字
姓
用户名
1.
做记号
奥托
@mdo
2.
奥托
@TwBootstrap
123
3.
雅各布
桑顿
@肥
4.
小鸟拉里
@推特
abc
$('#mtable')。在('click','tbody tr',函数(事件)上{
$(this.addClass('highlight').sides().removeClass('highlight');
});
函数选择(rowID){
//在这里,我需要找到tr3并选择它。
}
在顶部我有一个链接(选择),单击时,我只需要选择第3行(突出显示)。换句话说,如果选择了其他行,则应取消选择该行,仅选择第3行。请问怎么做?
谢谢因为您使用的是jQuery,所以我删除了
onclick
属性。然后我添加了一个名为id
的data
属性,您将在这里放置id
将要定位的对象
$(函数(){
$('a')。在('click',function()上{
var id=$(this.data('id');
$('tr').removeClass('highlight');
$('#行'+id).addClass('highlight');
})
})
。突出显示{
背景颜色:绿色;
}
选择第1行
选择第2行
选择第3行
选择第4行
#
名字
姓
用户名
1.
做记号
奥托
@mdo
2.
奥托
@TwBootstrap
123
3.
雅各布
桑顿
@肥
4.
小鸟拉里
@推特
abc