jQuery的:为什么不是这个简单的jQuery块不工作?
$(document).ready(function() {
$("#links .button").click(function() {
var id = $(this).attr("id") + "-fade";
$("#sliding-blocks").fadeOut(100);
$("#" + id).fadeIn(300);
});
});
与简易HTML:
<table id="links">
<tr>
<td>
<div id="projects" class="button">
Projects
</div>
</td>
</tr>
</table>
<table id="sliding-blocks">
<tr>
<td>
<span id="projects-fade" class="block">
<img class="icon" src="github.png" height="20" width="20" />
</span>
</td>
</tr>
</table>
非精简HTML包含#links
和#sliding-blocks
,但所有的多个条目遵循同样的 “变脸” 命名约定。
出于某种原因,我不能得到任何工作(甚至没有我能工作的东西)。是的,我已经加载jQuery。
解决方案:
$(document).ready(function() {
var blocks = ["projects-fade", "blog-fade", "online-fade", "resume-fade"];
$("#links .button").click(function() {
var id = this.id + "-fade";
$("#sliding-blocks").fadeOut(100,function() {
$.each(blocks, function() {
$("#" + this).hide();
});
$("#" + id).show();
$(this).fadeIn(300);
});
});
});
你正在淡出包含你想要显示的元素的表 – frictionlesspulley 2012-02-11 18:00:23