2017-03-02 65 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

我不明白。你能否詳細說明 –

相關問題