如何获得我在bootbox.confirm()
内点击的li?
<ul id="something">
<li>Result 1</li>
<li>Result 2</li>
<li>Result 3</li>
</ul>
$('#something li').click(function(){
bootbox.confirm("Are you sure?", function(result) {
if(result == true){
alert("You deleted" + /*here I want to get the item that was clicked*/);
}
});
});
答案 0 :(得分:1)
使用this
缓存上下文:
$('#something li').click(function(){
var $this = this; // cache it here
bootbox.confirm("Are you sure?", function(result) {
if(result == true){
alert("You deleted" + $this.textContent/*use it here now!!*/);
}
});
});
答案 1 :(得分:0)
您可以在此上下文中使用$( this )
。
$('#something li').click(function(){
console.log($( this ));
});