可选择的Jquery和php

Selectable Jquery and php

本文关键字:php Jquery 可选择      更新时间:2023-09-26

我正在寻找一种方法来发送选定的项目到一个可选的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>                   

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

我不太明白。看起来您想要的是将每个选定列表项的索引号作为参数发送给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);
    });
})