好的,我有下面的代码,它会在某些点为字符串着色,使用 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/