jquery select option 设置selected属性

来源:互联网 发布:怎样赢网络棋牌机器人 编辑:程序博客网 时间:2024/05/16 15:53
//jquery选中selectfunction selectByValue(sltName,value){   $("select[@name="+sltName+"] option").each(function(){    if($(this).val() == value){    $(this).attr("selected","selected");    }    });   } //更直接:$("#sltName").val(data.topicVoteBean.maxCount); 


取值:
【引自:http://zhangyulong.iteye.com/blog/1328615】
var sex  = $("#search_form select[name='sex'] option:selected ").attr("value");var sex = $("#search_form select[name=sex'] option[selected]").attr("value");这样写会有问题 sex的值有时是undifined 改为var sex  = $("#search_form select[name='sex'] option:selected ").attr("value");var val = $("#search_form select[name='sex']").children('option:selected').val();这样就去到了
0 0
原创粉丝点击