通過使用:last
或:first
選擇不是選擇的第一但在li
此順序中的第一是我所管理的解決方案:
HTML
<ol class="selectable">
<li class="ui-widget-content"
id="selectable_1"
value="1"
> First Selectable </li>
<li class="ui-widget-content"
id="selectable_2"
value="2"
> Second Selectable </li>
</ol>
在這段代碼我給li
ID和價值,從而使它們可供選擇事件
JAVASCRIPT
//A place to put the last one
var last_selected_value;
var last_selected_id;
$(".selectable").selectable({
selecting: function(event, ui) {
//In the selection event we can know wich is the last one, by getting the id on
//the ui.selecting.property
last_selected_value = ui.selecting.value;
last_selected_id = ui.selecting.id;
},
stop: function(event, ui) {
//Here the event ends, so that we can remove the selected
// class to all but the one we want
$(event.target).children('.ui-selected').not("#" + last_selected_id)
.removeClass('ui-selected');
//We can also put it on a input hidden
$("#roles_hidden").val(last_selected_value);
}
});
的
ui
財產有沒有辦法使用「ui」參數獲取當前選擇?當使用stop:funtion(event,ui){}時,可選參數ui總是似乎未定義... – RYFN 2009-09-04 14:02:06-1這不是一個好方法。你應該使用$(ui.selected) – nima 2012-01-24 10:25:52
@nima我在想,近2.5年前,情況並非如此。發佈答案。 – 2012-01-24 14:41:18