2011-07-20 82 views
0

我一直在試圖找到一種方法來在他們之間交換選項值,而我正在使用jQuery UI。我做了一個簡單的小提琴,它可以交換選項,但只有當我不使用jQuery UI時纔有效。如何:在使用jQuery UI時使用jQuery交換選項

工作撥弄沒有 jQuery UI的加載上的選項:http://jsfiddle.net/mBMRp/

工作撥弄 jQuery UI的加載上的選項:http://jsfiddle.net/FUUYq/

非常感謝

+0

我們可以有更多關於上下文的信息嗎?也許有一種更簡單的方法來實現最終結果。 – balexandre

回答

2

你需要distroy selectMenu和重新綁定它看看這個fiddle

$('select').selectmenu(); 
$('.swap a').click(function() { 
    var opt1 = $(this).parent().prev('.forms').find('option'); 
    var opt2 = $(this).parent().next('.forms').find('option'); 

    // Remove them from the dom. 
    opt1.detach(); 
    opt2.detach(); 

    // And put them back. 
    $(this).parent().prev('.forms').find('select').append(opt2); 
    $(this).parent().next('.forms').find('select').append(opt1); 
    $('select').selectmenu('destroy').selectmenu(); 
}); 
+0

非常感謝先生。我只是理解這個概念。我雖然jQuery moto做得更多,但是寫得更少。 – jQuerybeast

相關問題