JQuery 如何在另一个对象中获取对象
How to get object inside another object in JQuery
如何获取我在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*/);
}
});
});
您可以在此上下文中使用 $( this )
。
$('#something li').click(function(){
console.log($( this ));
});
使用 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!!*/);
}
});
});
如何获取我在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*/);
}
});
});
您可以在此上下文中使用 $( this )
。
$('#something li').click(function(){
console.log($( this ));
});
使用 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!!*/);
}
});
});