2013-10-20 8 views
0

나는 CURL을 통해 특정 웹 사이트의 전체 이미지를 얻고 PHP 루프 안에 넣는 PHP 코드를 가지고 있습니다. I가 버튼을 클릭하면jQuery에서 PHP 배열의 값을 얻는 방법

는 는 다음 prev/ next 버튼 표시되는 현재 화상과 배열을 스캔 할 수있는 사용자에 표시 될

$('$current_image').val(1);

$.post("curl_fetch.php?url="+ extracted_url, { 
    }, function(response){ 
    $('#loader').html($(response).fadeIn('slow')); 
    $('#current_image').val(1); // insert loop value in .val() 

난 싶어

$z=1; 
for ($i=0;$i<=sizeof($images_array);$i++) { 
    ....<img src = "$images_array[$i]" id="$z"> .. 
    $z++; 
    } 
배열의 값, 지금하지 루프 값

$(function() { 
    $(document).on('click','.submit', function() { 
    var img = $('#current_image').val(); //get the array value, not the loop value 
    alert(img); 
});}); 

, 내가 제대로 내의 배열 값을 얻는 방법 Jquery의

답변

0

질문이 약간 혼란 스럽지만 컬을 사용하여 이미지 목록을 가져온 다음 jQuery를 사용하여 하나씩 페이지를 넘길 수있는 것처럼 들립니다. 이 작업을 수행하는 한 가지 방법은 이미지 URL의 자바 스크립트 배열을 만든 다음 해당 배열을 사용하여 img src 값을 업데이트하는 것입니다.

<!-- load the page with the first image --> 
<img src="<?php echo $images_array[0]; ?>" id="visible_img"></img> 
<button id="previous"><< previous</button> 
<button id="next">next >></button> 

<!-- setup a javascript array of images and listen for clicks --> 
<script type="text/javascript"> 
     var curIdx = 0; 
     var imageUrls = ["<?php echo implode('","', $images_array); ?>"]; 

     // display the previous image (if there is one) 
     $("#previous").click(function() { 
       if (curIdx > 0) { 
         curIdx--; 
         $("#visible_img").attr("src", imageUrls[curIdx]);  
       } 
     });  

     // display the next image (if there is one) 
     $("#next").click(function() { 
       if (curIdx < imageUrls.length - 1) { 
         curIdx++; 
         $("#visible_img").attr("src", imageUrls[curIdx]);  
       } 
     });  
</script> 
관련 문제