Using jQuery .live to populate a dropdown and selecting an item.

See [here][1] if you want to see what I am doing. I can get a dropdrop list to load from a JSON source, but when I select an item the list reloads again. I know what the problem is, I just don't know the solution. $("#RequestType").live("click", function() { var items = ""; $.each(jsonRequestType, function(i, item) { items += ""; }); $("#RequestType").html(items); }); I know the problem is "click", but I don't know what I should use instead. *Update new related problem* The only problem I have now is when the edit page loads, I have to reselect my data in each drop down. How do I get the drop down to load when I load the page? **Working Code thus far minus problem above** The display <%= Html.Hidden("RequestType", Model.DayRequested.RequestType, new { Class = "RequestTypeValue" })%> <%= Html.DropDownList("RequestTypeDdl", new List { new SelectListItem { Text = "(Select)", Value = "" } }, new { Class = "RequestTypeDdl" })%> And the script // Get the request types for the drop down $(".RequestTypeDdl").live("focus", function() { var items = ""; var field = $(this); $.each(jsonRequestType, function(i, item) { items += "

以上就是Using jQuery .live to populate a dropdown and selecting an item.的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JSON 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准