2013-07-16 38 views
0

對不起張貼了類似我的前一個職位,但我認爲我的解釋並不好。jQuery和CakePHP的 - 如何傳遞參數在我的jQuery函數

其實,我有我的觀點的CakePHP

這適用於特定視圖使用jQuery函數。

我希望能夠通過傳遞參數(我想要的jQuery函數爲運行的div id來使用與其他視圖這個jQuery功能。

我的問題是,它的變化,我需要在我的功能做,以它的工作原理,以及如何將它從我的觀點(語法請)調用。

我希望這個網站的專家幫助,我不能在文檔中找到答案。

這裏是我的jquery功能

$(function 
    { 
     // Hide the first cell for JavaScript enabled browsers. 
     //$('#link-data td:first-child').hide(); 

     $('#moreWrapper ').hover(function() 
     { 
     $(this).toggleClass('Highlight'); 
     }); 

     // run after page loads  
     $("#more").hide(); 


     // Assign a click handler that grabs the URL 
     // from the first cell and redirects the user. 
     $('#moreWrapper ').click(function() 
     { 

     $(this).toggleClass("active").next().slideToggle(100); 
     return false; //Prevent the browser jump to the link anchor 

     }); 


    }); 
0在這種情況下,「moreWrapper」,然後就迴應:
+0

除非有一些顯著不同 - 請編輯你的存在的問題。 – AD7six

+0

[在cakephp的查詢函數中傳遞參數]的可能重複(http://stackoverflow.com/questions/17578971/passing-parameters-in-query-function-in-cakephp) – AD7six

回答

0

從控制器動作給div來視圖名稱:

$this->set('div', 'moreWrapper'); 

這樣你將有你的看法至極提供的$ DIV變量保存它到你的jQuery選擇:

所以你只要取代#<?php echo $div ?>

$('#<?php echo $div ?>').hover(function() 
{ 
    $(this).toggleClass('Highlight'); 
}); 
0

使用此代碼在您的控制器的動作替換#moreWrapper

$this->set('domElement', 'moreWrapper_or_some_other_name'); 

在對應的視圖文件,使用下面的代碼:

<script type="text/javascript"> 
$(document).ready(function(){ 

<?php if(!empty($domElement)) {?> 

    // Hide the first cell for JavaScript enabled browsers. 
    //$('#link-data td:first-child').hide(); 
    $('#<?php echo $domElement;?>').hover(function() { 
     $(this).toggleClass('Highlight'); 
    }); 

    // run after page loads 
    $("#more").hide(); 

    // Assign a click handler that grabs the URL 
    // from the first cell and redirects the user. 
    $('#<?php echo $domElement;?>').click(function() { 
     $(this).toggleClass("active").next().slideToggle(100); 
     return false; //Prevent the browser jump to the link anchor 
    }); 

<?php }?> 

    //other javascript code implementation here...... 
}); 
</script>