【问题标题】:Writing jQuery Drag & Drop selection into PHP Variables将 jQuery 拖放选择写入 PHP 变量
【发布时间】:2014-01-28 15:19:18
【问题描述】:

我已经实现了图像 Drag an Drop,如下例所示:http://jqueryui.com/droppable/#photo-manager。我已经为每个图像元素添加了 ID,这样我就可以创建一个已丢弃元素的列表,并为那些保持不变的元素创建另一个列表。

我真的可以使用一些帮助来将选定和非选定的 id 导入 PHP 下降发生后的变量。

开始 UL 图库(可拖动)带有 id 的图像元素,例如:

  <ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix">
    <li class="ui-widget-content ui-corner-tr">
      <img src="img/gler.png" alt="lake" width="96" height="32" id="2">
      <a href="link/to/trash/script/when/we/have/js/off" title="Delete this image" class="ui-icon ui-icon-trash">Delete image</a>
    </li>
  </ul>

垃圾箱 DIV(可丢弃)

  <div id="trash" class="ui-widget-content ui-state-default">
 <h4 class="ui-widget-header"><span class="ui-icon ui-icon-trash">Trash</span>       Trash</h4>
  </div>

【问题讨论】:

    标签: php jquery-ui drag-and-drop jquery-ui-draggable jquery-ui-droppable


    【解决方案1】:

    使用 javascript,您需要在每个容器中构建一个 id 数组,如下所示:

    var selected = [],
        unselected = [];
    $('#gallery img').each(function(){
        selected.push($(this.attr('id'));
    });
    $('#trash img').each(function(){
        unselected.push($(this.attr('id'));
    });
    

    您可以使用事件触发此操作,例如每次放置后或用户单击完成按钮时,等等。现在将这些数组传递给您喜欢的服务器(刷新页面或 ajax 调用)。

    【讨论】:

    • 嗨 Joe42,我迷路了……我已经声明了我的脚本,如:&lt;script type='text/javascript'&gt; $(document).ready(function(){ $('#MyButton').click(function(){ var selected = [], unselected = []; $('#gallery img').each(function(){ selected.push($(this.attr('id')); }); $('#trash img').each(function(){ unselected.push($(this.attr('id')); }); }); }); &lt;/script&gt; 和一个按钮,如:&lt;input type="button" value="Capacity Chart" id="MyButton" &gt; 如果这很好,请你帮我传递数组到字符串?在此先感谢,很抱歉要求太多。
    猜你喜欢
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多