2017-02-01 7 views
0

私のアプリケーションでjqueryスライダーを使用しています。入力された入力タイプに画像URLパスがあります。 "#1 IMG-パス - " 私は するvar image_path_id =に "jqueryで一意の番号を持つdivのIDを取得するには?

img-paths- <?php echo $omsg_id; ?> 

" $ omsg_id値を取得したい+ $(この).dataセクション( 'ID');

私は火のバグで印刷コンソール、出力はそれを解決する方法#1 IMG-パス-未定義

でしたか?

<div class="post-image"> 
       <?php $imagePathArray = explode(',',$uploads); ?> 
<input id="img-paths-<?php echo $omsg_id; ?>" type="hidden" value="<?php echo htmlentities(json_encode($imagePathArray)); ?>" /> 
     <div id="gallery7-<?php echo $omsg_id; ?>" ></div> 
        <script> 
     $(function(e) { 

      var image_path_id = "#img-paths-"+$(this).data('id'); 
      var show_gallery_id = "#gallery7-"+$(this).data('id'); 
      console.log(show_gallery_id); 
      console.log(image_path_id); 

      $(show_gallery_id).imagesGrid({ 
       images:$.parseJSON($(image_path_id).val()), 
       align: true, 
       getViewAllText: function(imgsCount) { return 'View all' } 
      }); 

     }); 

    </script> 

        <!--<img src="<?php //echo $contentimage; ?>" class="image show-in-modal" alt="image post">--> 
        <p><?php echo $message; ?></p> 
       </div> 

答えて

1

this$(this).data('id')従って、所望のデータを返さない、windowオブジェクトを指します。

$omsg_idを直接スクリプトで使用できます。

var image_path_id = "#img-paths-<?php echo $omsg_id; ?>"; 
var show_gallery_id = "#gallery7-<?php echo $omsg_id; ?>"; 
+0

ありがとう@Saptalそれは働いた! – Sayuj3

関連する問題