我試圖通過使用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