欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

前端jq设置下拉框的,单选框,复选框的帖子

程序员文章站 2022-07-02 18:06:02
$(function(){ var sex=$("#sex").val(); var marriageStatus=$("#marriageStatus").val(); var education=$("#education").val(); if(!isnull(sex)){ $("input: ......

$(function(){
var sex=$("#sex").val();
var marriageStatus=$("#marriageStatus").val();
var education=$("#education").val();
if(!isnull(sex)){
$("input:radio[name='sex'][value="+sex+"]").attr('checked','true');
}
if(!isnull(marriageStatus)){
$("input:radio[name='marriageStatus'][value="+marriageStatus+"]").attr('checked','true');
}
if(!isnull(education)){
$("#education1 option[value='"+education+"']").attr("selected", true);
}
});
<input type="hidden" id="sex" value="${serviceInfo.sex}"/>
<input type="radio" name="sex" value="0" checked="checked"/>男
<input type="radio" name="sex" value="1"/>女
<input type="hidden" id="marriageStatus" value="${serviceInfo.marriageStatus}"/>
<input type="radio" name="marriageStatus" value="0" checked="checked"/>是
<input type="radio" name="marriageStatus" value="1"/>否
<input type="hidden" id="education" value="${serviceInfo.education}"/>
<select name="education" id="education1">
<option value="硕士">硕士</option>
<option value="本科">本科</option>
<option value="大专">大专</option>
<option value="其它">其它</option>
</select>
详细介绍请查看全文:https://cnblogs.com/qianzf/
原文博客的链接地址:https://cnblogs.com/qzf/