2011-09-22 3 views
1

제출 청취자를 iframe의 모든 양식에 첨부해야하지만 jQuery를 사용할 수 없습니다.제출 청취자를 jQuery없이 모든 양식에 첨부하는 방법

이 작업을 수행하는 가장 좋은 방법은 무엇입니까? 이미지가로드 될 때까지 대기해야하므로 시간이 걸릴 수 있기 때문에 차라리 window.onload을 사용하지 않을 것입니다. 분명히 $(document).ready()은 완벽했을 것입니다.하지만 제가 말했듯이 jQuery를 사용할 수는 없습니다.

감사

답변

1

Onload가 트릭을 수행합니다. 마틴의 jQuery 접근법은 더 빠를 것이다.

for(var i=0; i<document.forms.length; i++){ 
    var form = document.forms[i]; 
    form.addEventListener("submit", myListener,false); 
} 
+0

그럼 당신은 두 질문 모두에 완벽하게 답변했습니다. 나는 그것을 받아들입니까? –

+0

글쎄, 너에게 달렸어. 나는 당신의 주요한 질문에 대답했습니다. 당신을 가장 도운 것으로 받아들이십시오. –

1

그냥 롤 자신 :) 여기에 jQuery를 당신이 필요로하는 것을 가지고, 준비 이벤트를 위해 사용하는 코드는, 그것은 무료 (단에서 나온 코드에서 언급 할)의

bindReady: function() { 
     if (readyList) { 
      return; 
     } 

     readyList = jQuery._Deferred(); 

     // Catch cases where $(document).ready() is called after the 
     // browser event has already occurred. 
     if (document.readyState === "complete") { 
      // Handle it asynchronously to allow scripts the opportunity to delay ready 
      return setTimeout(jQuery.ready, 1); 
     } 

     // Mozilla, Opera and webkit nightlies currently support this event 
     if (document.addEventListener) { 
      // Use the handy event callback 
      document.addEventListener("DOMContentLoaded", DOMContentLoaded, false); 

      // A fallback to window.onload, that will always work 
      window.addEventListener("load", jQuery.ready, false); 

     // If IE event model is used 
     } else if (document.attachEvent) { 
      // ensure firing before onload, 
      // maybe late but safe also for iframes 
      document.attachEvent("onreadystatechange", DOMContentLoaded); 

      // A fallback to window.onload, that will always work 
      window.attachEvent("onload", jQuery.ready); 

      // If IE and not a frame 
      // continually check to see if the document is ready 
      var toplevel = false; 

      try { 
       toplevel = window.frameElement == null; 
      } catch(e) {} 

      if (document.documentElement.doScroll && toplevel) { 
       doScrollCheck(); 
      } 
     } 
    }, 
관련 문제