var $this = $(this); // 生成选项列表 var html = ''; html += '<div class="select-picker-container">'; html += '<div class="select-picker-search">'; html += '<div class="select-picker-search-checked">请选择</div>'; html += '</div>'; html += '<div class="select-picker-options-wrp">'; html += '<div class="select-picker-options-serch">'; html += '<input type="text" placeholder="">'; html += '</div>'; html += '<div class="select-picker-options-list">';
// 检查selectedValues中是否有不在options中的值 var missingValues = []; for (var j = 0; j < selectedValues.length; j++) { var selectedValue = selectedValues[j]; var found = false; for (var k = 0; k < options.length; k++) { if (options[k].value === selectedValue) { found = true; break; } } if (!found) { missingValues.push(selectedValue); } }
// 增加红色提示并列出不存在的值 if (missingValues.length > 0) { html += '<div><div style="color:red; font-size: smaller;"> 以下选择值不存在或者失效:<br></div>'; for (var l = 0; l < missingValues.length; l++) { var selected = 'duihao-no'; html += '<div class="select-picker-options-list-item">'; html += '<b class="' + selected + '"></b>'; html += '<span style="color: red;">' + missingValues[l] + '</span>'; html += '</div>'; } html += '</div>' }
for (var i = 0; i < options.length; i++) { var option = options[i]; var value = option.value; var text = option.text; var selected = ($.inArray(value, selectedValues) !== -1) ? 'duihao-checked' : 'duihao-nocheck'; // 检查是否被选中 html += '<div class="select-picker-options-list-item" data-value="' + value + '">'; html += '<b class="duihao ' + selected + '"></b>'; html += '<span>' + text + '</span>'; html += '</div>'; };