【问题标题】:Jquery sortable: Replace value text of input A by value of Input B if input A is in the first listJquery sortable:如果输入A在第一个列表中,则用输入B的值替换输入A的值文本
【发布时间】:2012-10-10 04:30:56
【问题描述】:

我正在使用可排序的 Jquery。

  • 我有一个不在两个列表中的第一个输入调用“Iwanttogetavalue”。
  • 我有两个可在彼此之间拖动的列表。
  • 输入是项目
  • 在第一个列表中只能拖动一个项目(输入)。

    如果可拖动输入(项目)(具有名为“giveavalue”的类)在第一个列表 (sortable1) 中,我希望输入“Iwanttogetavalue”从该输入中获取值。

    这是我的代码:

    <input type="text" id="Iwanttogetavalue">
    
    <ul id="sortable1" class="connectedsortables">
    </ul>
    
    <ul id="sortable2" class="connectedsortables">
       <li><input type="text" class="giveavalue"></li>
       <li><input type="text" class="giveavalue"></li>
    </ul>
    
    
    
    
    <script>
    $(function() {
    $("#sortable1").sortable({
        connectWith: '.connectedsortables',
        receive: function(event, ui) {
            if ($(this).children().length > 1) {
                //ui.sender: will cancel the change.
                //Useful in the 'receive' callback.
                $(ui.sender).sortable('cancel');
            }
        }
    })
    $("#sortable2").sortable({
        connectWith: '.connectedsortables',
        receive: function(event, ui) {
            if ($(this).children().length > 10) {
                //ui.sender: will cancel the change.
                //Useful in the 'receive' callback.
                $(ui.sender).sortable('cancel');
            }
        }
    }).disableSelection();
    });
    </script>
    

    谢谢!

  • 【问题讨论】:

    • 你知道 inputA 的值是多少吗?
    • 是的,会手动编写
    • 好的...我会相应地写一个回复。

    标签: jquery jquery-ui jquery-ui-sortable


    【解决方案1】:

    您可能希望将其放入接收函数中,以便每次排序时都会调用它...

    $('li .general_title').each(function () {
       var this_input = $(this);
       var id = this_input.attr('id');
       var value = this_input.val()
       if (id == "inputA") {
          $('#inputB').val(id);
       }
    } 
    

    如果您有任何问题,请告诉我。

    【讨论】:

    • 实际上,这对我不起作用或者我没有正确使用它。
    • Brian Noah,我刚刚编辑了我的问题,我想这更容易理解
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 2012-07-30
    相关资源
    最近更新 更多