我能夠遍歷我的選擇框:JQuery的 - 使用做點事同時選中和未選中複選框
$('#sel_driver_file_options :selected').each(function(i, selected) {
//console.log($(this).val());
var driverName = $(this).val();
var driverText = $(this).text();
$("#tr_file_options_input").show();
$("#span_" + driverName).show();
$('<div id="desc_file_options_input_' + driverName + '">Enter a Value For ' + driverText + '</div>').prependTo($("#span_" + driverName));
}); // end selected each
但我怎麼沒有被選擇的「#sel_driver_file_options」中執行所有複選框動作?
我所要做的是去掉補充說:
$('<div id="desc_file_options_input_' + driverName + '">Enter a Value For ' + driverText + '</div>').prependTo($("#span_" + driverName));
當用戶取消選擇它。否則,如果他們再次選擇它,則會創建第二個。
編輯:JSFiddle for the full block of code I am working on
EDIT2:更新的jsfiddle,重新寫了表,優化管理,改變了關閉功能,以這樣的:
close: function (event, ui) {
$('#sel_driver_file_options :selected').each(function (i, selected) {
var driverName = $(this).val();
var driverText = $(this).text();
var driverSpan = $("#span_" + driverName);
var driverDesc = $("#desc_" + driverName);
console.log("Selected = " + driverName);
$("#tr_file_options_input").show();
$(driverSpan).show();
$(driverDesc).show();
}); // end each selected
$('#sel_driver_file_options').not(':selected').each(function() {
//if ($('#sel_driver_file_options').not(':selected')) {
var driverName = $(this).val();
var driverText = $(this).text();
var driverSpan = $("#span_" + driverName);
var driverDesc = $("#desc_" + driverName);
console.log("Not Selected = " + driverName);
$(driverSpan).hide();
$(driverDesc).hide();
// driverSpan.find('[id^="desc_file_options_input_"]').remove();
}); // end each not selected
//$('#desc_file_options_input_' + driverName).remove();
} //end close function
現在控制檯顯示:
Selected = default-priority
Not Selected = default-priority
就好像not(':selected')不工作?
你可以創建一個HTML工作撥弄包括 –
中添加了問題的鏈接 –