Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery $(此)的值随确认而更改_Jquery - Fatal编程技术网

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;
    }
});