问题
I'm a beginner in Jquery and I cannot find out the solution to my problem.
In cakephp, I have a view where I call my jquery script in the following way:
<?php echo $this->Js->click; ?>
the jquery function is the following
$(function ()
{
$('#toogle-data').hover(function ()
{
$(this).toggleClass('Highlight');
});
$('#toggle-data').click(function ()
{
$("#more").hide();
$(this).toggleClass("active").next().slideToggle("normal");
});
});
This works fine.
But when I want to pass parameter, it does not work
in the view I replace the above call by
<?php echo $this->Js->click('#toggle-data'); ?>
and I change the first line of my jquery funnction as the following
$(function (x)
I got the following message
JsHelper:: Missing Method click is undefined [CORE\Cake\View\Helper\JsHelper.php
Thanks for your help
回答1:
click isn't a method
If you want to use the Js helper, then probably you'll need syntax similar to:
$this->Js->get('#toogle-data')->event('click', $eventCode);
Though, from the code in the question you don't need this helper at all - it's for generating appropriate event handlers which are already present in the javascript code.
回答2:
@AD7six is correct in that click is not a method of JsHelper.
What you're trying to achieve would be best done by creating your own helper.
With your own helper you could create a method that returns the click function.
来源:https://stackoverflow.com/questions/17578971/passing-parameters-in-query-function-in-cakephp