简体   繁体   中英

I want to pass a parameter from jQuery.click() method

<script type='text/javascript'>

            $(window).load(function() {
                $(document).ready(function() {
                    $('table tr').each(function() {
                        if ($(this).find('td').eq(6).text() === 'Start') {
                            $(this).css('background', 'yellow');
                            $(this).addClass('Start_Point');
                            $(this).click(a);
                        }
                    });
                });
            });

            function a()
            {
                alert();
            }

        </script>

I want send this object to my method using .click ..

I am already do following bt its not work . the method a() is calling when the function match case for 'start' which is wrong i want when user click on table the function a() will call

<script type='text/javascript'>

            $(window).load(function() {
                $(document).ready(function() {
                    $('table tr').each(function() {
                        if ($(this).find('td').eq(6).text() === 'Start') {
                            $(this).css('background', 'yellow');
                            $(this).addClass('Start_Point');
                            $(this).click(a(this));//This 
                        }
                    });
                });
            });

            function a()
            {
                alert();
            }

        </script>

You can pass an anonymous callback function as the click handler which will call the method a with desired parameters

$(this).click(function(){
    a(this)
});

try this

$(function(){
$(this).click(function(){
    a(this)
});
})

then u can try

$('.Start_Point').click(function(){
    a(this)
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM