1つのonClickでリンクなど変更箇所先が2つ以上

■1つのonClickで、リンク先が2つ以上あるとき
1つのonClickで、変更したい画像が2つ以上あるとき

別窓サンプル>>





テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト


■ソース(変更させるリンクの書き方)
<a href="javascript:;" onclick="
document.getElementById('img1').src='4.jpg';
document.getElementById('img2').src='5.jpg';
document.getElementById('img3').src='6.jpg';
">文字</a>

変更先のimgやiframeのIDを振る
変更後のパスを書く


■ソース(変更になる先の画像やiframe)
<img id="img1" src="1.jpg" />
<img id="img2" src="2.jpg" />
<img id="img3" src="3.jpg" />


IDを振る
デフォルトのパスを書く

-------------------



【応用編というか雑談というか】
document.getElementById('img1')style.display='block';
divのstyle属性のdisplay:none;をdisplay:block;にするとかもアリです。

Comments:0

Comment Form

Trackbacks:0

TrackBack URL for this entry
http://www.otogawa.com/cms/mt-tb.cgi/250
Listed below are links to weblogs that reference
1つのonClickでリンクなど変更箇所先が2つ以上 from px*blog