php - 使用复选框打开和关闭颜色 div

标签 php javascript jquery css

好的,我有下面的代码,它会在某些点为字符串着色,使用 divs 内部的 divs。

$lines = file("oneModelResults.txt");

$ntArr = array();
$oneHit= array();
// Loop the file data and build an multidimensional associative array
foreach ($lines as $line_num => $columns) {
  $line= explode("\t",$columns);

$allModels[$line[3]] = 1;
$oneHit = array(
  'hit' => $line[2],
  'name' => $line[0],
  'score' => $line[1],
  'end' => $line[2] + 3,
  'model' => $line[3],
  'top' => $line[5],
  'color' => getcolor(rawtransform($line[1]),$line[4]));


for ($i=0;$i<=3; $i++){
        $ntArr[$line[2]+$i][$line[3]][] = $oneHit;
  }
}

 // Close the file
fclose($fp);

// Generate a random sequence
$seqArr = array('A', 'T', 'C', 'G');
$randseq = array();
for ($i = 0; $i < 1000; $i++) {
$randseq[] = $seqArr[array_rand($seqArr)];
}

//main div for results visual
echo'<div id="coltext" style="font-family:monospace;font-size:17px;background-color:#D0D0D0;color:black;">'."\n";   


  // Iterate over $allModels and echo checkboxes
 foreach ($allModels as $modName => $value) {

echo '<input ModelName="'.$modName.'" type="checkbox" checked="checked"
onclick="toggle.apply(this);" />'.$modName.';

 }



// An array to track the current hits
$currentHits = array();
$modelArr=array();
foreach ($randseq as $index => $nuc) {
echo'<div class="seqWrap"title="position:'.($index+1).'">';
// Increment $index
$index++;



// Check whether we are at the start of a new hit
  if (isset($ntArr[$index]) and !empty($ntArr[$index])) {
  $currentHits[$index] = $ntArr[$index];
}

  if (count($currentHits)) {
      foreach($currentHits as $modelNameArr){
        foreach($modelNameArr as $hit){

          $hitCount = count($hit);
          $height=25/$hitCount;
          $counter=0;
          foreach($hit as $hitAttribute){
            $top = $height * $counter;

            $counter++;

            $color=$hitAttribute['color'];

            $op=($hitAttribute['score']/1000);
            $lborder=($index==$hitAttribute['hit']) ?
            "solid white 2px":"solid transparent 2px";
            $rborder=($index==$hitAttribute['end']) ?
            "solid white 2px":"solid transparent 2px";

              echo '<div class="hit" modName="'.$hitAttribute['model'].'"
            title="position:'.$newindex.',score:'.$hitAttribute['score'].'"
            color="'.$color.'" style="background:'.$color.';
            border-right:'.$rborder.';border-left:'.$lborder.';
            opacity:'.$op.';height:'.$height.'px;top:'.$top.'px;">';

            echo "</div>";

          }

        }
      }
  }
  //wrap nucleotide in div. 
  echo'<div class="nucWrap">'.$nuc."</div>"; 

// Split into 50 character chunks        
if (($index % 50 )==0){
  echo"<br />";
}
echo "</div>";

$currentHits=array();
}

 echo "</div>";

我想说以下内容:如果未选中复选框(类名=“模型名”),则隐藏具有属性“ModName=模型名”的 div,即如果类名 =Modname,则隐藏 div,但是我认为我的问题是浏览文档,.有人可以帮忙吗?

最佳答案

你可以在客户端试试这个。

[jQuery] 假设你有一个 jQuery 库加载到你的脚本中,在关闭正文之前将它放在你的 html 页面的末尾。

<script type="text/javascript">
    $(document).ready(function(){
     if($(".ModelName").attr("checked")=="checked"){
       // is checked
        $("div.ModelName").show();
     }else{
       // not checked
        $("div.ModelName").hide();
     }
    });
</script>

但是如果你需要不输出剩余的 html,如果 .ModelName 有属性检查,你需要用 PHP 处理,做一个 IF 语句来检查它。

已编辑:
进行了一些更改以隐藏具有类 ModelName 的元素,我正在使用 jQuery,因为它更简单易用。

关于php - 使用复选框打开和关闭颜色 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11099127/

相关文章:

php - 解析错误 : syntax error, 意外 'pname' (T_STRING) in C :\XAMPP\htdocs\testsubmit. php 第 22 行

php - 从 MySQL 中获取大量数据。将其插入 Redis 缓存。无法增加 PHP 内存限制

javascript 对象数组的迭代逻辑异或?

javascript - 主干网自动渲染 View ,这是不合需要的

php - Mysql 选择值然后更新

php - SailsJS 中的水线似乎没有捕捉到唯一约束

javascript - 幽灵博客不创建 RSS 提要

javascript - 从选定的复选框中获取输入值并将其显示在 url 框中

javascript - asp.net Jquery.ajax 保留 JSON.Parse 意外字符错误

jquery - 将鼠标悬停在表格行上在单元格之间移动时触发