我正在通过php创建一些复选框,像这样:
$query = mysql_query("SELECT user FROM login");
while ($row = mysql_fetch_assoc($query)) {
$readUser = $row['user'];
if($readUser == "mod"){}
else {
$checkboxUserId = $readUser;
echo "<p><input class='filled-in item' type='checkbox' id='$checkboxUserId' checked='checked' /><label for='$checkboxUserId'>Team: $checkboxUserId</label></p>";
}
之后的一些代码,我做:
我正在通过基于我存储在数据库中的一些值的Javascript函数绘制一些多边形。
$query = mysql_query("SELECT * FROM questionAnswers");
while ($row = mysql_fetch_assoc($query)) {
$readUser = $row['user'];
$someMoreVars = $row['var']; //like ten more or that
if ($user == "mod"){
if ($readUser == "mod"){}
else{
echo "drawUserPoly($someMoreVars, $iDontWantToListThemAll, $thatsJustForTheContext)";
//Some More Code here
}
现在的问题:我需要检查复选框,其中一个被选中,所以我不画它们,这需要实时更新(如:再次检查复选框,多边形将被绘制,取消复选框,多边形不被绘制)。
我的尝试:
else {
if(isset($_POST['$readUser'])){
echo "drawUserPoly($someMoreVars, $iDontWantToListThemAll, $thatsJustForTheContext)";
}
}
my second try:
else {
if($_POST['$readuser'] == 'checked'){
echo "drawUserPoly($someMoreVars, $iDontWantToListThemAll, $thatsJustForTheContext)";
}
}
请记住,所有PHP代码都是在页面发送到浏览器之前执行的,PHP无法看到在此之后页面上发生的任何事情。因此,PHP和HTML不能实时交互。
你的解决方案是使用Javascript,其中查看HTML和CSS样式中发生了什么。一种简单的方法是在JavaScript中选中事件的复选框上注册一个事件侦听器。当框未选中时,只需通过应用具有display:none
样式的CSS类来隐藏多边形。当复选框被选中时,删除该类,多边形将重新出现。