---
title: "多选择项类型字段存储与查询(二)"
author: "pipe"
date: "2009-07-07T13:41:31Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2009-07-07T13:41:31Z"
id: 421221
url: "https://pipe.iteye.com/blog/421221"
---

接上面

比如说 数据库中存储的值为7，如果要取到这个值然后塞到各个checkbox里面更新。
见代码：

```java

<script type="text/javascript" src="scripts/jquery.js">

</script>
<script type="text/javascript">
	$("body").ready(function(){	
	var a=7 //这个值是从数据库中查出的字段
	if(a&1) $("#c1").attr("checked",true);
	if(a&2)  $("#c2").attr("checked",true);
	if(a&4) $("#c3").attr("checked",true);
	})

</script>


<input type="checkbox" id="c1" value=1/>11<br>
<input type="checkbox" id="c2" value=2/>22<br>
<input type="checkbox" id="c3" value=4/>33<br>
</BODY>


```


如果为7 这3个checkbox都会勾选上。如果值为2 ，只会勾选c2.