开发者

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

开发者 https://www.devze.com 2023-04-08 12:43 出处:网络
I need to set the this as a default value for my list boxcan any body help me out. thanks $(document).ready(function () {

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

精彩评论

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