111이라는 폴더를 만들어 거기에 이미지를 넣고
밑에 소스처럼 111이라는 버튼을 생성 111버튼을 누르면 111폴더안에있는 이미지를 보여지게할려고하는데
버튼을 눌러도 이미지가 나오지가않아요... 잘못한건가요?
function tab_change(num) { var tab_content; for (var i=1; i<=9; i++) { tab_content = document.getElementById("tab_content"+i); if (i==num) { tab_content.style.display = ""; } else { tab_content.style.display = "none"; } }}</script> <div id="shop"> <input type="button" name="tab_radio" value="111" style="width:115px" onclick="tab_change(1)" /> <input type="button" name="tab_radio" value="222" style="width:115px" onclick="tab_change(2)" /> <input type="button" name="tab_radio" value="333" style="width:115px" onclick="tab_change(3)" /> <input type="button" name="tab_radio" value="444" style="width:115px" onclick="tab_change(4)" /></div></div><? $path = "./111"; $entrys = array(); $dirs = dir($path); while(false !== ($entry = $dirs->read())){ if(($entry != '.') && ($entry != '..')) { if(!is_dir($path.'/'.$entry)) { $entrys[] = $entry; } } } $dirs->close(); ?> <hr> <? foreach($entrys as $img){ ?> <div id="tab_content1" style="background-image:url(./111/<?=$img?>)"> </div> <? } ?>
답변 2개 / 댓글 1개
<? $path = "./img"; $entrys = array(); $dirs = dir($path); $cnt = 0;while(false !== ($entry = $dirs->read())){ if(($entry != '.') && ($entry != '..')) { if( !is_dir($path.'/'.$entry) ) { $entrys[] = $entry; $cnt++; } }}$dirs->close();?> <script>function tab_change(num) { var tab_content; for (var i=1; i<=<?=$cnt?>; i++) { tab_content = document.getElementById("tab_content"+i); if (i==num) { tab_content.style.display = ""; } else { tab_content.style.display = "none"; } }}</script> <div id="shop"><? for( $i=1; $i <= $cnt; $i++ ) { ?> <input type="button" name="tab_radio" value="<?=($i.$i.$i)?>" style="width:115px" onclick="tab_change(<?=$i?>)" /><? } ?></div></div><hr> <?$i = 1;foreach($entrys as $img){ ?> <div id="tab_content<?=$i++?>" style="position:absoulte; display:none"><img src="./img/<?=$img?>" /></div><? } ?>
tab_content 에서 이미지를 background로 넣고 싶으면 width, height가 안잡혀서 레이어 자체가 공간이 없음. 그래서 이미지가 안보임.
번외
$i = 0;
echo ++$i => 1이 찍힘
echo ++$i 는 $i = $i + 1; echo $i; 와 같음
$i = 0;
echo $i++ => 0이 찍힘
echo $i++ 는 echo $i; $i = $i + 1; 와 같음
답변에 대한 댓글 1개
<div id="tab_content1" style="background-image:url(./111/<?=$img?>)"> </div>
여기서 tab_content1 아이디도 증가되야 하는거 아닌가요? 고정이 아니라
답변을 작성하려면 로그인이 필요합니다.