Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 使用jQuery.live填充下拉列表并选择项目_Json_Drop Down Menu_Jquery - Fatal编程技术网

Json 使用jQuery.live填充下拉列表并选择项目

Json 使用jQuery.live填充下拉列表并选择项目,json,drop-down-menu,jquery,Json,Drop Down Menu,Jquery,看看你是否想看看我在做什么 我可以从JSON源获取要加载的下拉列表,但是当我选择一个项目时,列表会再次加载。我知道问题是什么,只是不知道解决办法 $("#RequestType").live("click", function() { var items = "<option selected>(Select)</option>"; $.each(jsonRequestType, function(i, item) { items += "

看看你是否想看看我在做什么

我可以从JSON源获取要加载的下拉列表,但是当我选择一个项目时,列表会再次加载。我知道问题是什么,只是不知道解决办法

$("#RequestType").live("click", function() {
    var items = "<option selected>(Select)</option>";
    $.each(jsonRequestType, function(i, item) {
        items += "<option value='" + item.Id + "'>" + item.Title + "</option>";
    });
    $("#RequestType").html(items);
});
$(“#请求类型”).live(“单击”,函数(){
var items=“(选择)”;
$.each(jsonRequestType,函数(i,项){
项目+=“”+项目.标题+“”;
});
$(“#请求类型”).html(项目);
});
我知道问题是“点击”,但我不知道应该用什么来代替

更新新的相关问题我现在唯一的问题是当编辑页面加载时,我必须在每个下拉列表中重新选择我的数据。当我加载页面时,如何让下拉列表加载

迄今为止的工作代码减去上述问题

显示器

<td><%= Html.Hidden("RequestType", Model.DayRequested.RequestType, new { Class = "RequestTypeValue" })%>
    <%= Html.DropDownList("RequestTypeDdl", new List<SelectListItem> { new SelectListItem { Text = "(Select)", Value = "" } }, new { Class = "RequestTypeDdl" })%></td>

剧本呢

// Get the request types for the drop down
$(".RequestTypeDdl").live("focus", function() {
    var items = "<option>(Select)</option>";
    var field = $(this);
    $.each(jsonRequestType, function(i, item) {
        items += "<option value='" + item.Id + "'";
            if ($(field).prev("input").val() == item.Id)
                items += " selected";
            items += ">" + item.Title + "</option>";
        };
    });
    $(this).html(items);
});

$(".RequestTypeDdl").live("change", function() {
    $(this).prev("input").val($(this).val());
});
//获取下拉列表的请求类型
$(“.RequestTypeDdl”).live(“焦点”,函数(){
var items=“(选择)”;
变量字段=$(此字段);
$.each(jsonRequestType,函数(i,项){
项目+=“”+项目.标题+“”;
};
});
$(this).html(项目);
});
$(“.RequestTypeDdl”).live(“更改”,函数(){
$(this.prev(“input”).val($(this.val());
});

试试“聚焦”或“改变”,也许吧。

嗯?期望的结果是什么?Focus通过组合“更改”来保存价值。