私はフィールドセットの境界線を残し、その伝説がクリックされるフィールドセットの内容の表示を切り替えますjQueryの関数は、凡例は表示している:崩壊のフィールドセット
$('legend.togvis').click(function() {
$(this).siblings().toggle();
return false;
});
フィールドセットにテキストノードが含まれていないとうまくいきません。最初の関数と同じように動作します
$('legend.togvis').click(function() {
$(this).parent().contents().not('legend').toggle();
return false;
});
:テキストを切り替えるための努力で
<fieldset><legend class='togvis'>Click Me</legend>
<p>I toggle when the legend is clicked.</p>
But I'm a recalcitrant text node and refuse to toggle.
</fieldset>
はあまりにも私はこれを試したノード。そして、この:
エラーをスロー$('legend.togvis').click(function() {
$(this).parent().contents(":not(legend)").toggle();
return false;
});
Message: 'style.display' is null or not an object
Line: 5557
Char: 3
Code: 0
URI: http://code.jquery.com/jquery-1.4.4.js
フィールドセット(マイナス伝説)伝説がクリックされたときに切り替えるの全体の内容を取得する方法上の任意の考えは?
<fieldset>
<legend class='togvis'>Click Me</legend>
<div class="contents">
<p>I toggle when the legend is clicked.</p>
But I'm a recalcitrant text node and refuse to toggle.
</div>
</fieldset>
は次に、あなただけのdivを切り替える必要があります。Eibx
$('legend.togvis').click(function() {
$(this).parent().contents().filter(
function() { return this.nodeType == 3; }).wrap('<span></span>');//wrap any stray text nodes
$(this).siblings().toggle();
});
テキストノードにはスタイルがない/できないという問題があるようです。 '.toggle()'はノードのcssに影響を与えて動作するので、テキストノードに影響を与えることはできません。おそらく、私はフィールドセットの内容を '.data()'に格納し、子を削除する必要がありますか? – dnagirl