2012-02-11 92 views
0

我想要做這樣的事情。cakephp Js助手

如果我點擊一些,它會顯示另一個DIV (id='#busy-indicator')

我寫了以下內容,但它不起作用。

$this->Js->get('#some-link')->event('click', $this->Js->get('#busy-indicator')->effect('fadeIn')); 

什麼應該糾正才能使它工作?

它生成以下輸出。

$(document).ready(function() { 
    $("#busy-indicator").bind("click", function (event) { 
     $("#busy-indicator").fadeIn(); 
     return false; 
    }); 
}); 
+0

你是否包括jQuery的?它不會被CakePHP自動包含。此外,使用'$ this-> Js-> writeBuffer();'在視圖/佈局的底部檢查是否正在編寫JavaScript緩存。 – 2012-02-11 20:29:33

+0

是的,我已經包含了jQuery和$ this-> Js-> writeBuffer();已經在佈局的底部。 – gautamlakum 2012-02-12 07:22:00

回答

1

您可以使用這樣的 「兩步走」 的解決方案:

$event = $this->Js->get('#busy-indicator')->effect('fadeIn'); 

$this->Js->get('#some-link')->event('click', $event); 

這是HTML輸出:

$(document).ready(function(){ 
    $("#some-link").bind("click", function(event) { 
    $("#busy-indicator").fadeIn(); 
    return false; 
    }); 
});