且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从可在PHP中选择的jQuery UI获取值

更新时间:2023-02-23 22:33:13

jQuery UI文档中进行了部分修改的段

$(function() {
    $( "#selectable" ).selectable({
        stop: function() {
            var result = $( "#select-result" ).empty();
            $( ".ui-selected", this ).each(function() {
                var index = $( "#selectable li" ).index( this );
                // send an AJAX request to a PHP file
                $.get('myphpfile.php', {
                    selectedIndex: index
                }, function(data) {
                    // do stuff with the results from PHP
                });

            });
        }
    });
});

编辑

要通过按钮执行此操作

$(function() {
    $( "#selectable" ).selectable();

    $("submit[name=Submit1]").click(function() {
        var index = $( "#selectable li" ).index( $("#selectable") );
        $.get('myphpfile.php', {
            selectedIndex: index
        }, function(data) {
            // do stuff with the results from PHP
        });
    });
});