2012-06-19 2 views
0

확인 div의 내부에서 div를 사용하여 특정 지점에서 문자열에 색상을 지정하는 코드가 있습니다. 체크 상자를 사용하여 색상 구분선을 켜고 끕니다.

$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>"; 

나는 다음 saythe 할 (클래스 명 = "MODELNAME"가) 확인란을 선택하지 않으면 속성 "모듈 이름 ="MODELNAME ""즉, 클래스 이름이 모듈 이름, 숨기기 = 경우가 있습니다 사업부를 숨길 div, 그러나 내 문제는 문서를 탐색하는 것입니다. 아무도 도와 줄 수 있습니까?

+0

그냥 조용히 : http://stackoverflow.com/questions/439110/is-it-alright-to-add-custom-html-attributes – phenomnomnominal

답변

1

클라이언트 측에서 시도해 볼 수 있습니다.

[jQuery] 귀하의 스크립트에 jQuery 라이브러리가로드되었다고 가정하면 본문을 닫기 전에 HTML 페이지 끝 부분에 배치하십시오. 당신이 .ModelName이 선택 속성 경우 출력을 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> 

하지만, 당신은 PHP로 처리를 확인하는 IF 문을 확인해야합니다.

편집가 :
더 간단하고 쉽게 사용할 수 있기 때문에, 내가 jQuery를 사용하고 클래스 MODELNAME을 가지고있는 요소를 숨기기 위해 일부 변경했습니다.

+0

나는 위의 사용을 시도했지만 작동하지 않았다, Ive는 Jquery를 사용하지 않았다. , 그래서 확실하지,하지만 난 그냥 내 코드의 머리에 위의 추가하고 그것을 그대로 둡니까? – user1338194

+0

예, 특정 요소를 타겟팅하기 위해 선택기에서 더 잘 작동하고 싶다면 hide() 및 show() 자신을 설명하십시오 – Gntem

+0

무슨 뜻입니까? – user1338194

관련 문제