방법이 없을까요? 제가 너무 프로그래밍에 초짜라
본문
<script>
$(document).ready(function(){
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) - (88*2) + $(window).scrollTop()) + "px");
return this;
}
//사진닫기
$("#showcase").click(function(){
$(this).css("display", "none");
});
});
//사진보기
function showImg(e){
var e;
$(".bimgs").remove();
alert(e);
$("div#showcase").append(e);
$("#showcase").center();
$("#showcase").css("display", "block");
//var ff = $(".bimgs").attr("src");
}
//end
</script>
<?php
for ($i=0; $i<count($list); $i++) {
$file = get_file($bo_table, $list[$i]['wr_id']);
$thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);
for($j=0; $j<$file['count']; $j++) {
$img_src[$j] = "<img src='".$file[$j]['path']."/".$file[$j]['file']."'>";
}
// for ($i=0; $i<$list_count; $i++) {
// $thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);
if($thumb['src']) {
$img = $thumb['src'];
// $image = $thumb['ori'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
// $wr_href = get_pretty_url($bo_table, $list[$i]['wr_id']);
?>
<td class="images">
<dl>
<dt>Images</dt>
<dd><a href="javascript:;" onclick="showImg(<?php echo $img_src[0]; ?>)" class="clip" alt=""><?php echo $img_content; ?></a></dd>
</dl>
</td>
위에처럼 코딩하면 다음처럼 showImg () 안에 이미지 주소를 가져오는데요. 스크립트가 안먹혀요. 얼럿을 왜 안띄우는건지 이미지 경로만 가져와지면 좋겠는데 <img> 안붙이니까 에러나서 어떻게 이미지 주소만 가져올지 모르겠어요. view.skin.php에서 파일 부르는 코드를 넣어봤는데두 에러만 납니다.
<dd>
<a href="javascript:;" onclick="showImg(<img src='http://dreamuse.net/data/file/gallery/1982826859_4ir2UXlG_476ebdf309ea89a714284bfc84c01ab6bfcdc118.png'>)" class="clip" alt=""><img src="http://dreamuse.net/data/file/gallery/thumb-1982826859_4ir2UXlG_476ebdf309ea89a714284bfc84c01ab6bfcdc118_360x260.png" alt="" title=""></a>
</dd>
답변 3
alert이 안 뜨는 이유는 함수안에 들어가는 파라미터 값이 잘못 들어갔기 때문 입니다.
저렇게 감싸는게 맞는지 헷갈리는데;;저쪽이 문제이니 한번 살펴보세요.
onclick="showImg('<img src="http://dreamuse.net/data/file/gallery/1982826859_4ir2UXlG_476ebdf309ea89a714284bfc84c01ab6bfcdc118.png">')"
그리고 경로만 가져오시려면
for($j=0; $j<$file['count']; $j++) {
$img_src[$j] = "<img src='".$file[$j]['path']."/".$file[$j]['file']."'>";
}
위의 코드 중 $file[$j]['path']."/".$file[$j]['file']
값을 활용하시면 됩니다.
<a href="javascript:;" onclick="showImg( '<?php echo
htmlspecialchars($img_src[0]); ?>')" class="clip" alt=""><?php echo $img_content; ?></a>
이렇게 하세요.
우선 for 루프가 닫히지 않았네요
49라인정도
}
?>
for 루프 닫는 중괄호(}) 가 빠졌습니다.
답변을 작성하시기 전에 로그인 해주세요.