我需要将用户选择的文本保存到db.I尝试了3种不同的方式,但是所有这些方法都为选中的方法返回null 值。 value1或value2或value3返回null。我在这做错了什么?
<div id="reasonsList" style="display: none">
@foreach (var reason in Model.CorrectionReasonsList)
{
<option>@(reason)</option>
}
</div>
var value = '<option selected="selected" value="' + sData + '">' + sData + '</option>';
var reasonsSelect = '<select id="correction_reason_dropdown" ' +
'multiple ' +
'style="min-width:115px" ' +
'data-select-options={"searchField":"false","noValueText":"Select One"))"} ' +
'class="select multiple-as-single compact correction-reason" ' +
'>';
reasonsSelect += value + $("#reasonsList").html();
reasonsSelect += "</select>";
$(nTd).html(reasonsSelect);
var value1 = $('#reasonsList:selected').val();
var value2 = $('#reasonsList:selected').find('option:selected').text();
var value3 = $('#reasonsList:selected').text();
答案 0 :(得分:1)
您需要从下拉列表中选择文本,而不是div
。下面的代码应该:
$("#correction_reason_dropdown:selected").text();