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("")
精彩评论