簡體   English   中英

我想從jQuery.click()方法傳遞參數

[英]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>

我想使用.click將這個對象發送到我的方法中。

我已經在追隨它的不工作了。 當函數'start'匹配大小寫時,方法a()正在調用,這是錯誤的,我希望當用戶單擊表時函數a()將調用

<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>

您可以傳遞一個匿名回調函數作為單擊處理程序,它將使用所需參數調用方法a

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

嘗試這個

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

那你可以嘗試

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM