テーブルを表示または非表示にするこのシンプルなJQuery関数があります。表示/非表示は機能しますが、イメージ(プラス/マイナス)は変更されません。シンプルなjQueryの表の表示/非表示
テーブルは次のようである:
<span id="collapsible">These are some
new titles.
<table id="data">
<tr>
<th colspan="3">2008</th>
</tr>
<tr>
<td>As You Like It</td>
<td>Comedy</td>
<td></td>
</tr>
<tr><th colspan="3">2007</th><tr>
<tr>
<td>Henry IV, Part I</td>
<td>History</td>
<td>1596</td>
</tr>
<tr>
<td>Sunit Joshi</td>
<td>History</td>
<td>2010</td>
</tr>
</table>
</span>
jQueryの関数である:
$(document).ready(function() {
var collapseIcon = 'images/minus.png';
var collapseText = 'Collapse this section';
var expandIcon = 'images/plus.png';
var expandText = 'Expand this section';
var $subHead = $('#collapsible');
$subHead.prepend('<img src="' + expandIcon + '" alt="' + expandText + '" class="clickable" />')
$subHead.click(function(){
$('#data').toggle();
($('#data').is(':hidden')) ? $(this).attr('src', expandIcon) : $(this).attr('src', collapseIcon);
return false;
});
$subHead.css('cursor', 'pointer')
.click();
})。
ここで何が間違っている可能性がありますか。画像は最初の「+」状態のままです。
ありがとう
スパン要素をクリックできるように#折り返し可能です。 – Sunit
申し訳ありません私はスパンのIDを見ませんでした。 – MitMaro
ありがとうございます。あなたはそれを再現できますか?それはとてもシンプルですが動作しません。ナッツを運転する.. !! – Sunit