0

我正在寻找一种将所选项目发送到 Jquery 的可选项到 php 页面的方法

<script>
  $(function() {
    $( "#selectable" ).selectable({
      stop: function() {
        var result = $( "#select-result" ).empty();
        $( ".ui-selected", this ).each(function() {
          var index = $( "#selectable li" ).index( this );
          result.append( " #" + ( index + 1 ) );
        });
      }
    });
  });

  $(function() {
    $("#foo").submit(function(event){
        $.post('batch.php?page=rinomina', {selectable: $('#select-result').html()});
    });
  });
  </script>
  <script>
   $(function() {
    $( ".direct" )
      .button()
      .click(function( event ) {

      });
  });
  </script>

<form id="foo" action="" method="post">
    <a href="javascript:{}" class="direct"onclick="document.getElementById('foo').submit(); return false;">submit</a>                   

但这是错误的,不明白我错在哪里!

4

1 回答 1

0

不太确定我完全理解。您想要的是作为参数发送给 php 方法的每个选定列表项的索引号?您可以通过多种方式解决此问题。我能想到的最简单的方法是获取所选索引的索引,然后使用 jQuery 的 param 方法使它们的 URL 友好并添加到您的帖子 url。例如:

例子

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

    $("#foo").submit(function(e) {
        e.preventDefault();
        var ids = new Array();
        $("#selectable .ui-selected").each(function(i) { ids[i] = "# " + ($(this).index()+1); });

        // get values as URL parameters for passing to PHP
        var paramSelectable = $.param({ selectable: ids });

        //    easiest implementation with what you have
        $.post('batch.php?page=rinomina&'+paramSelectable);
    });
})
于 2013-05-06T16:46:56.330 回答