如何在用户选择的下拉列表项中设置?
场景:
1.用户未在表单中输入所有必需值
2.单击已发送.
3.页面刷新,未选中下拉列表中的值.如何选择价值?
我有工作脚本检索列表的数据.
$('#userid').select2({
placeholder : " --- select ---",
minimumInputLength: 2,
ajax: {
url: "index.php?modul=getusers",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: function (term, page) {
return {
q: term,
page_limit: 10
};
},
results: function (data, page) {
return { results: data };
}
},
allowClear: true,
formatSelection: function(data) {
return data.text;
}
});
Run Code Online (Sandbox Code Playgroud)
ajax调用中的标准数据:{"text":"示例文本","id":"1"}
输入:
<input type="text" value="<? echo $_POST['userid']; ?>" class="input" id="userid" name="userid">
我尝试添加以下代码,但它不起作用
initSelection: function(element, callback) {
var id=$(element).val();
if (id!=="") { …Run Code Online (Sandbox Code Playgroud)