根据数据库的值来判断页面上的开关是开或者是关(单选框);

今天遇到一个问题就是根据后台查数据库的返回值来判断页面上的单选框自动选定哪一个。

<input type="radio" id = "id1"  name = "rdo1" value = "T"/> 开启
<input type="radio" id = "id2"  name = "rdo1" value = "F"/> 关闭

<script type="text/javascript">
$.ajax({
	type: "post",
	url: '<%=request.getContextPath()%>/timeWork/selectonoff.so', //URL 地址 <%  %> 里面写Java代码
	cache:false,
	dataType:"json",
	success: function(msg){
            //msg是后台查询返回的数据值  开:T,关:T
		if (msg.successful) {
			var flag = msg.resultValue;
            // 返回信息
			if (flag == 'T') { //是否相等
				document.getElementById("id1").checked=true;
			} else {
				document.getElementById("id2").checked=true;
			}
		}
	}
});
</script>

猜你喜欢

转载自blog.csdn.net/cainiao_dashen/article/details/81395329