2011-05-13 6 views
0

Firefox에서 유효성 검사 오류가 표시되는 것은 Chrome 및 Safari에서 작동합니다.Firefox javascript error

이 원래 코드 :이 아이디 fterror와 사업부에 오류 메시지를 보낼 수있는 나의 새로운 자바 스크립트 코드가

function MM_validateForm() { //v4.0 
    if (document.getElementById){ 
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; 
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]); 
     if (val) { nm=val.name; if ((val=val.value)!="") { 
     if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); 
      if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; 
     } else if (test!='R') { num = parseFloat(val); 
      if (isNaN(val)) errors+='- '+nm+' must contain a valid number no spaces.\n'; 
      if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); 
      min=test.substring(8,p); max=test.substring(p+1); 
      if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; 
     } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } 
    } if (errors) alert('The following error(s) occurred:\n'+errors); 
    document.MM_returnValue = (errors == ''); 
} } 

이다;

function MM_validateForm() { //v4.0 
    if (document.getElementById){ 
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; 
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]); 
     if (val) { nm=val.name; if ((val=val.value)!="") { 
     if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); 
      if (p<1 || p==(val.length-1)) errors+=' '+nm+' must contain an e-mail address.\n'; 
     } else if (test!='R') { num = parseFloat(val); 
      if (isNaN(val)) errors+='- '+nm+' must contain a valid number no spaces.\n'; 
      if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); 
      min=test.substring(8,p); max=test.substring(p+1); 
      if (num<min || max<num) errors+=' '+nm+' must contain a number between '+min+' and '+max+'.\n'; 
     } } } else if (test.charAt(0) == 'R') errors += ' '+nm+' is required.\n'; } 
    } if (errors) document.getElementById('fterror').innerText = "Please correct the following error(s): \n"+errors; 
    document.MM_returnValue = (errors == ''); 
    if (errors == '') document.getElementById('fterror').innerText = ""; 
} } 
+3

. Dreamweaver를 사용하여 새 규칙을 다시 설정할 수 있습니다. 그렇지 않은 경우 스크립트의 정확한 차이를 정확하게 찾아야합니다. 그러면 더 쉽게 도움을 얻을 수 있습니다. –

+0

코드를 형식화하고 오류를 나타내는 "실제"예제를 제공하고 예상 한 내용과 실제로 발생하는 내용을 정확하게 설명하십시오. 또한 전화 또는 관련 HTML을 보지 않고도 크리스탈 볼을 가지고있는 사람들을 기다리고 있습니다. 내가 말할 수있는 한 두 코드 사이의 유일한 차이는 다음과 같은 하이픈이다 :'errors + = '-'+ nm + ''. 문자열에 하이픈을 삽입하는 것 외에이 코드를 실행 한 결과에 큰 영향을 미치지 않을 것이라고 생각합니다. – RobG

+0

답장을 보내 주셔서 감사합니다. 유일한 변화는 3 줄의 코드입니다. 오류 메시지가 경고 상자에 표시되지만 div 태그에 오류를 기록하고 싶습니다. – ollie

답변

0

당신은 파이어 폭스에서 작동하려면 innerHTML 대신 innerText을 설정해야합니다

하나 심각하게 코드의 조각을 엉망
document.getElementById('fterror').innerHTML = ... 
+0

요청에 따라 변경했으며 모두 작동합니다. 도움 주셔서 대단히 감사합니다 :)))) – ollie