【发布时间】:2018-05-22 05:55:31
【问题描述】:
我有一个类似这样的 html 页面:
<div class="list-group-item" style="border-left: none; border-right: none;">
<img src="./img/desktop.png" height="25" width="25">
<a class="a-file">testcase.txt</a>
<button class="btn btn-default btn-sm btn-current" style="float: right;">
<span class="glyphicon glyphicon-ok-circle span-current"></span>
</button>
<button class="btn btn-default btn-sm btn-star" style="float: right;">
<span class="glyphicon glyphicon-star-empty span-star"></span>
</button>
</div>
当用户单击其中一个按钮时,我想获取<a> 中存在的文件名。我试过这样做,但它不起作用:
$(document).on('click','.btn-current',function(){
var file = $('.btn-current').closest('.a-file').text();
alert(file);
});
【问题讨论】:
-
像
var file = $(this).prev('.a-file').text();一样使用.prev()
标签: javascript jquery html css twitter-bootstrap-3