2014-01-15 4 views
0

에서만 작동합니다내가이 JS 사용하는 파이어 폭스

이 파일의
var RowT = 1; 

function toggleRowT() { 
    if (RowT == 0) { 
     window.document.getElementById('t1').style="display:table-row;"; 
     window.document.getElementById('t2').style="display:table-row;"; 
     window.document.getElementById('t3').style="display:table-row;"; 
     window.document.getElementById('letter_t').style="opacity:1;"; 
     RowT = 1; 
    } else if (RowT == 1) { 
     window.document.getElementById('t2').style="display:none;"; 
     window.document.getElementById('t3').style="display:none;"; 
     window.document.getElementById('t1').style="display:none;"; 
     window.document.getElementById('letter_t').style="opacity:0.2;"; 
     RowT = 0; 
    } 
} 

var RowD = 1; 

function toggleRowD() { 
    if (RowD == 0) { 
     window.document.getElementById('d1').style="display:table-row;"; 
     window.document.getElementById('d2').style="display:table-row;"; 
     window.document.getElementById('d3').style="display:table-row;"; 
     window.document.getElementById('d4').style="display:table-row;"; 
     window.document.getElementById('letter_d').style="opacity:1;"; 
     RowD = 1; 
    } else if (RowD == 1) { 
     window.document.getElementById('d1').style="display:none;"; 
     window.document.getElementById('d2').style="display:none;"; 
     window.document.getElementById('d3').style="display:none;"; 
     window.document.getElementById('d4').style="display:none;"; 
     window.document.getElementById('letter_d').style="opacity:0.2;"; 
     RowD = 0; 
    } 
} 

: http://flamencopeko.net/bpm_calc.js

이 페이지의 : http://flamencopeko.net/bpm_calc.php

http://www.jslint.com에 붙여 위의 코드는 너무 많은 오류 발생 그들을 나열하십시오. 그러나 공백 누락 같은 모든 이상한 물건 등 === 대신 ==의 사용이다

이 다른 브라우저에서 작동하지 않습니다 두 개의 버튼에 대한 HTML입니다 :

<a href="javascript:toggleRowT();"><img src="/ico/letter_t.gif" class="ico" alt="X" title="toggle triplets" id="letter_t">triplets</a> 

<a href="javascript:toggleRowD();"><img src="/ico/letter_d.gif" class="ico" alt="X" title="toggle dotted" id="letter_d">dotted</a> 

이를 CSS는 : http://flamencopeko.net/flame_style.css

누구나 문제가 있습니까?

+1

당신은'php'를 사용하고 있습니다 : P –

+0

당신을 믿습니다. 나는 이상한 사람이다. ;) 좋은 분. 재미있는 파이어 폭스는 그 코드를 해석 할 수있다. –

답변

3

요소의 style 속성은 문자열이 아니며 개체입니다. 당신이 스타일 개체의 display 속성을 설정하려면 다음과 같이 그렇게 :

window.document.getElementById('d1').style.display = "none"; 
// Note display is a property of style ---^    ^
// And there's no ; at the end of the value -------------/ 

은 (그리고 유사 opacity을 설정할 때.) 파이어 폭스에서 작동하는 경우

는, 파이어 폭스 특수 처리 할 때이 있어야합니다 속성에 문자열을 할당합니다.


그리고 난 그냥 최소한의 재 작성을 저항 할 수

function toggleRow(type) { 
    var elm, n; 
    var display, opacity; 

    // Loop through the rows 
    for (n = 1; n <= 3; ++n) { 
     // Get this row 
     elm = document.getElementById(type + n); // t1/d1, t2/d2, t3/d3 

     // If it's the first, figure out the values to use 
     if (n === 1) { 
      if (elm.style.display === "none") { 
       display = "table-row"; 
       opacity = "1"; 
      } 
      else { 
       display = "none"; 
       opacity = "0.2"; 
      } 
     } 

     // Set the display 
     elm.style.display = display; 
    } 

    // And the opacity 
    document.getElementById("letter_" + type).style.opacity = opacity; 
} 

HTML :

더 컨텍스트와
<a href="javascript:toggleRow('t');"><img src="/ico/letter_t.gif" class="ico" alt="X" title="toggle triplets" id="letter_t">triplets</a> 

<a href="javascript:toggleRow('d');"><img src="/ico/letter_d.gif" class="ico" alt="X" title="toggle dotted" id="letter_d">dotted</a> 

, 나는 우리가 완전히 id의 제거 할 수 내기 코드를 더 짧게 만드십시오.

+0

실제로. 최고 감사합니다! 현재 모든 브라우저에서 완벽하게 작동합니다. –

+0

지금 다시 써보세요. 너무 멋져요. 고맙게 생각합니다. –

+0

4 개의 점으로 구분되어 있으므로'n <= 3;'을'n <= 4; '로 변경하려고했습니다. 이로 인해 D 버튼이 투명 해지지 않습니다. 몇 줄을 더 추가 할 계획입니다. 그리고 Ds와 Ts의 수가 동등한 지 나는 불확실합니다. 나는 대부분의 코드를 이해하고 있으며, 나는 그것이 들어가기위한 방향이라는 것에 상당히 확신한다. elm은 요소의 짧은 부분이고 n은 숫자의 짧은 부분이다, 네? –