2017-03-02 68 views
0

我将一个值id传递给javascript函数。这里的id正在打印。如何将id从javascript传递到codeigniter中的引导模型?

<script> 
    function openModal(id) { 
    document.getElementById('myModal').style.display = "block"; 
    var img_id = id; 
    document.getElementById('caption').innerHTML = img_id; 
    } 
</script> 

现在我想将这个值传递给引导模式

<div id="myModal" class="modal"> 
    <button type="button" id="close" onclick="closeModal()">close</button> 

    <div class="modal-content"> 
    <div class="mySlides"> 

    <?php  

    //here i want to use this id with if condition so that desired image is 
    //displayed.With for each all images are coming. 
    //$project_images = explode(",", $value['project_gallery']); 

    $project_images = json_decode($value['project_gallery'],true); 

    foreach ($project_images as $project_image_value) { 
    ?> 

    <img src="<?= base_url() ?>assets/uploads/projects/<? =$project_image_value['fname']?>" style="width:100%"> 

    <?php 
    } 
    ?> 
    </div> 
</div> 
</div> 

是有可能。如果真让我知道。

+0

你能更具体吗? – user218046

+0

我想将img_id从javascript函数传递到引导模型,以便我将在模型中使用 –

+0

您要在哪里确定该id在模型中? – user218046

回答

0

在引导模式添加一个隐藏字段像

<input type="hidden" id="img_id" name="img_id"> 

,并添加脚本

function openModal(id) { 
$("#img_id").val(id); 
document.getElementById('myModal').style.display = "block"; 
var img_id = id; 
document.getElementById('caption').innerHTML = img_id; 

}

因此,在模型你要通过

值为1个的场img_id
+0

如何获取使用php隐藏的输入值使用 –

+0

您必须使用GET/POST将js变量发送到php –

+0

我不明白。你能否详细说明 –

相关问题