我试图通过使用jQuery来更改表的按钮的文本。问题是,jQuery .is(":visible")
似乎没有做到这一点。我究竟做错了什么?我认为.is(":visible")
是需要检查一个元素是否可见。jQuery:根据表的可见性状态更改按钮的文本
$(function() {
$("#tabla").hide(); // We start hiding it.
$("#boton").click(function() {
var tabla = $("#tabla");
tabla.fadeToggle();// Change the table visibility
// An tell us if it is visible or not
if (tabla.is(":visible")) {
alert("It's visible"); // This is always called.
// TODO Change button text.
} else {
alert("It isn't visible"); // This is never called.
// TODO Change button text.
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<p><button id="boton">Show</button></p>
<table id="tabla" >
<thead>
<tr><th id="cabecera">First</th><th>Second</th></tr>
</thead>
<tbody>
<tr>
<td>Foo</td><td>Boo</td>
</tr>
</tbody>
</table>
谢谢!这正是问题。感谢您发现了移动的问题;-) – PhoneixS 2014-10-31 10:41:02