我想知道为什么$(this)
不能像我期望的那样工作?在下面的代码中,当你点击“删除图像”时,没有任何反应。如果您注释掉了确认语句,则当您单击“删除图像”时,背景将变为绿色。你知道为什么吗?由于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");
});
发布于 2013-05-18 11:11:29
您在设置css之前返回,所以该行不会被执行。尝试:
$('.the-one').click(function(){
if (confirm("What do you say?")) {
$(this).css("background", "green");
return true;
} else {
return false;
}
});
发布于 2013-05-18 11:10:42
因为在它之前已经有了return
。return
之后的所有东西都不会运行。
https://stackoverflow.com/questions/16620292
复制相似问题