Javascript JQuery UI的默认选择问题';可选';

Javascript JQuery UI的默认选择问题';可选';,javascript,jquery,Javascript,Jquery,下面是我的JS。当页面加载时,我希望它自动运行函数,就像被点击一样。默认选择使其处于已选择状态,但不会启动该功能。你知道怎么做吗 $(function() { $( "#selectable" ).selectable({ selected: updatefilters }); function updatefilters(ev, ui){ // get the selected filters var templ

下面是我的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') 
});

谢谢

尝试运行body标记中的函数

<body onload="name_of_function()">

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

$(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(); 
});

当他有权访问
$(document.ready()
;时,没有充分的理由建议使用内联javascript;