开发者

how to set the default value to the list box using jquery

I need to set the this as a default value for my list box can any body help me out.

thanks

  $(document).ready(function () {
            var targetid = '<%:ViewData["target"] %>';
            if (targetid != null) {
                $("#lstCodelist").val(tar开发者_运维百科getid); //// I need to set this targetid as default selected value for lstCodelist
            }


Set n to the index of the item you wish to set as selected.

$("#lstCodelist option").eq(n).attr('selected','selected')


This should do it:

$('#foo').val(2)

http://jsfiddle.net/yRXEc/


$("#ListBox")[0].selectedIndex = 0


It is worked for me. You can try it

$("#foo").val("")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜