0

下面是我的 JS。当页面加载时,我希望它自动运行该功能,就好像它被点击一样。默认选择使其开始被选中,但不启动该功能。关于如何使它工作的任何想法?

$(function() {
    $( "#selectable" ).selectable({
        selected: updatefilters  
    });   
    function updatefilters(ev, ui){
        // get the selected filters
        var template, html;
        var pagego;
        if(! pagego){
        var page = 0; 
        }
        var $selected = $('#selectable').children('.ui-selected');
        // create a string that has each filter separated by a pipe ("|")
        var filters = $selected.map(function(){return this.id;}).get().join("\|");
        $.ajax({
            type: "POST",
            url: 'updatefilters',
            dataType: 'json', 
            data: { filters: filters, page: page },
            success: function(data){
                html = "Do Something";
                $('#board').html(html); 
            }
        });
    }
    $('#lets').addClass('ui-selected') 
});

谢谢!

4

2 回答 2

2

只需在声明后调用该函数:

$(function() {
    $( "#selectable" ).selectable({
        selected: updatefilters  
    });   
    function updatefilters(ev, ui){
        ...
    }
    $('#lets').addClass('ui-selected');

    // none of your params are consumed in the function anyways, so you don't need to pass anything
    updatefilters(); 
});
于 2012-05-10T17:50:26.973 回答
0

尝试在body标签中运行函数

<body onload="name_of_function()">
于 2012-05-10T17:44:34.820 回答