Home > Backend Development > PHP Tutorial > 请问一个关于php数组有关问题

请问一个关于php数组有关问题

WBOY
Release: 2016-06-13 12:16:09
Original
996 people have browsed it

请教一个关于php数组问题




请问你怎么实现,数据库里存在的值 在页面里就让checkbox选中
------解决思路----------------------

<br /><script src="http://code.jquery.com/jquery-1.8.0.js" type="text/javascript"></script><br /><script><br />var text="bb,aa,cc,dd";//把数据库的查找内容用,拼接放这<br />$(document).ready(function(){<br />	//遍历所有checkbox,当其值存在在text中时选中<br />	$(":checkbox").each(function() {<br />		text=","+text+",";//防止匹配到bbb<br />        if(text.indexOf(","+$(this).val()+",")!=-1) $(this).prop("checked",true);<br />    });<br />});<br /></script><br /><br /><input type="checkbox" value="aa" />1<br /><input type="checkbox" value="bb" />2<br /><input type="checkbox" value="bbb" />3<br />
Copy after login

------解决思路----------------------
写错了,修改一下
<br /><script src="http://code.jquery.com/jquery-1.8.0.js" type="text/javascript"></script><br /><script><br />var text="bb,aa,cc,dd";//把数据库的查找内容用,拼接放这<br />$(document).ready(function(){<br />	text=","+text+",";//防止匹配到b<br />	//遍历所有checkbox,当其值存在在text中时选中<br />	$(":checkbox").each(function() {<br />        if(text.indexOf(","+$(this).val()+",")!=-1) $(this).prop("checked",true);<br />    });<br />});<br /></script><br /><br /><input type="checkbox" value="aa" />1<br /><input type="checkbox" value="bb" />2<br /><input type="checkbox" value="b" />3<br />
Copy after login

------解决思路----------------------
选项都应该是数据库里的,产生html页面时是枚举出来的,
你可以指定某些ID是选中的
while($row==mysql_fetch_row($res)){
if($row['id]==6)
   echo "";
else
   echo "";
}


------解决思路----------------------
看你结构,你应该先用explode(',', goods_brand); 获取到每一个goods_brand
然后再判断是否与当前的checkbox对应,如果是,加上checked="checked";

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template