Jquery $(此)的值随确认而更改
我想知道为什么Jquery $(此)的值随确认而更改,jquery,Jquery,我想知道为什么$(这个)没有按我期望的方式工作?在下面的代码中,单击“删除图像”时不会发生任何事情。如果您注释掉确认语句,则单击“删除图像”时背景将变为绿色。你知道这是为什么吗?由于confirm语句,似乎$(this)指向了其他内容。提前谢谢 <a href="#" class='thumbnail the-one delete-file'><i class="icon-remove"></i>Remove Image</a> $('.the-
$(这个)
没有按我期望的方式工作?在下面的代码中,单击“删除图像”时不会发生任何事情。如果您注释掉确认语句,则单击“删除图像”时背景将变为绿色。你知道这是为什么吗?由于confirm语句,似乎$(this)
指向了其他内容。提前谢谢
<a href="#" class='thumbnail the-one delete-file'><i class="icon-remove"></i>Remove Image</a>
$('.the-one').click(function(){
if(confirm("What do you say?")) { return true;} else {return false;}
$(this).css("background", "green");
});
$('.the one')。单击(function(){
if(确认(“你说什么?”){return true;}else{return false;}
$(this.css(“背景”、“绿色”);
});
因为前面有return
。返回后的所有内容都不会运行。在设置css之前返回,因此该行不会被执行。尝试:
$('.the-one').click(function(){
if (confirm("What do you say?")) {
$(this).css("background", "green");
return true;
} else {
return false;
}
});