开发者

How to set the default selection on the currently added item using jquery

I have this code using this code I am inserting an item from one list box to other list box. I need to set the default selection for tagrget list box item when it is added.

please can any body help me out how to set the deafult selection to the list box.

How to set the default selection to the currently added item to the list box

 function DoInsert(ind) {
            var sourceIndex = $("#lstAvailableCode").val(); /// Selected Item to add
            var targetIndex = $("#lstCodelist").val()开发者_运维知识库; /// added item to the list box(target list box)
            var success = 0;
            var rightSelectedIndex = $("#lstCodelist").get(0).selectedIndex;
            var functionName = "/Ajax/SaveCodeforInsert";
            if (ind == "plan") {
                functionName = "/Ajax/SaveCodeforInsertForPlan";
            }

            $.ajax({
                type: "POST",
                traditional: true,
                url: functionName,
                async: false,
                data: "ControlPlanNum=" + $("#ddControlPlan").val() + "&LevelNum=" + $("#ddlLevel").val() + "&ColumnNum=" + $("#ddlColumn").val() + "&SourcbaObjectID=" + sourceIndex + "&TargetbaObjectID=" + targetIndex + "&userID=<%=Model.userID%>",
                dataType: "json",
                error: function (data) {
                    alert("Error Adding Code");
                    FinishAjaxLoading();
                },
                success: function (data) {
                    if (data == 0) { success = 1; } else { success = data; }
                    FinishAjaxLoading();
                }
            });


could you use

.focus() 

Example:

$("#lstCodelist").focus();


you can use .focus in the success callback to set the focus

$("element").focus()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜