请教一个关于php数组问题 php数据库checkbox数组 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script src="http://code.jquery.com/jquery-1.8.0.js" type="text/javascript"></script><script>var text="bb,aa,cc,dd";//把数据库的查找内容用,拼接放这$(document).ready(function(){ //遍历所有checkbox,当其值存在在text中时选中 $(":checkbox").each(function() { text=","+text+",";//防止匹配到bbb if(text.indexOf(","+$(this).val()+",")!=-1) $(this).prop("checked",true); });});</script><input type="checkbox" value="aa" />1<input type="checkbox" value="bb" />2<input type="checkbox" value="bbb" />3 写错了,修改一下<script src="http://code.jquery.com/jquery-1.8.0.js" type="text/javascript"></script><script>var text="bb,aa,cc,dd";//把数据库的查找内容用,拼接放这$(document).ready(function(){ text=","+text+",";//防止匹配到b //遍历所有checkbox,当其值存在在text中时选中 $(":checkbox").each(function() { if(text.indexOf(","+$(this).val()+",")!=-1) $(this).prop("checked",true); });});</script><input type="checkbox" value="aa" />1<input type="checkbox" value="bb" />2<input type="checkbox" value="b" />3 选项都应该是数据库里的,产生html页面时是枚举出来的,你可以指定某些ID是选中的while($row==mysql_fetch_row($res)){if($row['id]==6) echo "<input type='checkbox' value=$res['goods_brand'] checked='checked'/>";else echo "<input type='checkbox' value=$res['goods_brand'] />";} 看你结构,你应该先用explode(',', goods_brand); 获取到每一个goods_brand然后再判断是否与当前的checkbox对应,如果是,加上checked="checked"; 为什么在服务器上面调用始终是unknown host mysql+php 会员 中文用户登陆问题 编译错误,求解 ==深圳==创业公司寻php的程序开发人员,兼职或者全职均可== 求两段php常用的简单代码,每段30分。 采用apahce的mod_write,url中包含中文会出现乱码(找了好久都没能解决) 求一个正则表达试,有关数字和字符。 php打包 请高手看看我的表单怎么不能提交呀 重整: php代码怎样重整?谁能提点意见? select下拉框的值传入jquery,并用ajax传到另一个php页面,老是传不过去。 (refcount=1, is_ref=1) 此时不能被unset
<script src="http://code.jquery.com/jquery-1.8.0.js" type="text/javascript"></script>
<script>
var text="bb,aa,cc,dd";//把数据库的查找内容用,拼接放这
$(document).ready(function(){
//遍历所有checkbox,当其值存在在text中时选中
$(":checkbox").each(function() {
text=","+text+",";//防止匹配到bbb
if(text.indexOf(","+$(this).val()+",")!=-1) $(this).prop("checked",true);
});
});
</script><input type="checkbox" value="aa" />1
<input type="checkbox" value="bb" />2
<input type="checkbox" value="bbb" />3
<script>
var text="bb,aa,cc,dd";//把数据库的查找内容用,拼接放这
$(document).ready(function(){
text=","+text+",";//防止匹配到b
//遍历所有checkbox,当其值存在在text中时选中
$(":checkbox").each(function() {
if(text.indexOf(","+$(this).val()+",")!=-1) $(this).prop("checked",true);
});
});
</script><input type="checkbox" value="aa" />1
<input type="checkbox" value="bb" />2
<input type="checkbox" value="b" />3
你可以指定某些ID是选中的
while($row==mysql_fetch_row($res)){
if($row['id]==6)
echo "<input type='checkbox' value=$res['goods_brand'] checked='checked'/>";
else
echo "<input type='checkbox' value=$res['goods_brand'] />";
}
然后再判断是否与当前的checkbox对应,如果是,加上checked="checked";