简体   繁体   中英

How do i pass an value to a function that i use as parameter?

i want to pass a function as an parameter if an element was clicked. But in the function that i pass i want to set an attribute information from the clicked element.

What is the best way to pass the attribute value to the inner of the function?

My JavaScript looks like this:

$('.edit-link').livequery(function(){
    $('.edit-link').click(function(){
        WMT.openOverlay($('#edit'),{
            relativeTo: $('.search'),
            width: $('.search'),
            close: $('#cancel_edit'),
            fillFields: function(){
                return $.getJSON("ajax/edit.php?id=" + $(clickedElement).data('id'));
            }
        });
    });
});

i want to send the data attribute "id" in the json.

You need to use this . It pointed to clicked element:

$(this).data('id')

If this didn't work try this:

var clickedElement = this;
WMT.openOverlay($('#edit'),{
// ... rest of your code.

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