从html获取id的值传递给php代码片段

时间:2016-11-28 14:56:54

标签: javascript php laravel-5

我试图将计数从html属性<h4 id=""></h4>传递给PHP代码。

是否可以操作或转换<h4 id=""></h4>到PHP,因为我需要id来获取计数以使用PHP块中的值。

@foreach($trans as $tran)
<tr>
 <td>{!! $tran->sponsor_id !!}</td>
 <td>{!! $tran->ship_id !!}</td>
 <th>                               
     <a class="btn" href="#" data-image-id="" data-toggle="modal" data-title="{!! $tran->tran_message !!}" 
        data-count="{!! count($tran['listImage']) !!}"
        data-target="#image-gallery"><button>View Info</button></a>
    </th>
</tr>                         
@endforeach

<script type="text/javascript">
    $(document).ready(function(){
        loadGallery(true, 'a.btn');
        function loadGallery(setIDs, setClickAttr){
            var current_image,
            selector,
            images,
            counter = 0;
            function updateGallery(selector) {
                var $sel = selector;
                images = $sel.data('count');

                current_image = $sel.data('image-id');


                $('#image-gallery-count').text($sel.data('count'));
                $('#image-gallery-caption').text($sel.data('caption'));
                $('#image-gallery-title').text($sel.data('title'));

                var b = (64 + parseInt(images.toString()));
                var a = 65;
                for (i = a; i <= b; i++) {   
                   var letter = String.fromCharCode(i);
                   $('#image-gallery-image-'+String.fromCharCode(i)).attr('src', $sel.data('image-'+String.fromCharCode(i)));
               };


               disableButtons(counter, $sel.data('image-id'));
           }

           if(setIDs == true){
            $('[data-image-id]').each(function(){
                counter++;
                $(this).attr('data-image-id',counter);
            });
        }
        $(setClickAttr).on('click',function(){
            updateGallery($(this));
        });
    }
});
</script>

//这是我需要进入php代码片段的计数

 <h4 id="image-gallery-count"></h4>

修改

我想使用id="image-gallery-count"的值传入forloop来控制循环的结束。

<div class="modal fade" id="image-gallery" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="image-gallery-title"></h4>
            </div>

          <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
              <!-- Wrapper for slides -->
              <div class="carousel-inner">
                  <?php 
 $value = "<h4 id='image-gallery-count'></h4>";


                  $c = chr(64 + 16);
                  $b = chr(64 + 1);
                  ?>  
                  <?php $first = true; ?>
                  @for ($i = $b; $i <= $c; $i++)
                  @if ( $first )
                  <div class="item active">
                      <img id="image-gallery-image-{!! $i !!}" class="img-responsive" src="">
                      <div class="carousel-caption">
                        One Image
                    </div>
                </div>
                <?php $first = false; ?>
                @else
                <div class="item">
                  <img id="image-gallery-image-{!! $i !!}" class="img-responsive" src="">

                  <div class="carousel-caption">
                    Another Image
                </div>
            </div>
            @endif
            @endfor

        </div>

        <!-- Controls -->
        <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left"></span>
        </a>
        <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right"></span>
        </a>
    </div>
          <div class="modal-footer">
          </div>

</div>
</div>
</div>

0 个答案:

没有答案