我认为这很简单:我只想让JS检测点击链接的子img是否具有某个src属性.如果是的话,做一件事.如果不是,请做另一件事.但由于某种原因,click事件完全忽略了if/else条件.如果.children()选择器和事件仍然执行就像条件为真,我可以放任何我想要的废话.我不太了解Jquery,所以我很茫然.任何帮助,将不胜感激.
$('.addcomp').click(function(){
if($(this).children('img[src="add.png"]')){
$(this).parents("tr").find('.compcost').addClass('cost').end().find('td:last-child,td:nth-child(3)').addClass('addcompbg');
$(this).children("img").attr("src","forbidden.png");
}
else if ($(this).children('img[src="forbidden.png"]'))
{$(this).parents("tr").find('.compcost').removeClass('cost').end().find('td:last-child,td:nth-child(3)').removeClass('addcompbg');
$(this).children("img").attr("src","add.png");
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
427 次 |
| 最近记录: |