2013-05-06 51 views
0

我正在尋找一種方式來選擇項目的jQuery選擇發送到PHP頁面可選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>     

,但它是錯誤的,不明白的地方我米錯了!

+0

'$ .POST( 'batch.php頁= rinomina?',{可選擇:$( '#選擇-結果')的HTML()});'是不通過你選擇的,它是通過用id元素的裏面寫整個HTML'選擇-result' – SpYk3HH 2013-05-06 15:06:19

+0

我想你想得是什麼樣的複選框?或者你真的想要通過所有的HTML?的想你想的PHP收到 – SpYk3HH 2013-05-06 15:08:46

+0

選擇一個或多個元素得到#1#2#3 ... 在PHP我想包含這些3個值一個簡單的變量需要更好地瞭解。我補充說。 HTML只是因爲它被建議給我。我該怎麼辦? – 2013-05-06 16:09:27

回答

0

不太清楚我完全理解。看起來你想要的是作爲參數發送到php方法的每個選定列表項的索引號?你可以通過很多方式去解決這個問題。我能想到的最簡單的方法就是獲取所選的索引,然後使用jQuery的param方法使它們對URL友好並添加到您的發佈網址。例如:

Example

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

不工作:(原始頁面batch.php,點擊按鈕,ID爲「foo」的提交表單,重定向到batch.php? – 2013-05-06 16:56:17