2012-11-07 7 views
0

페이지로드시 일부 jquery를 실행하려고하지만 현재 작동 중입니다. 링크가 이미 저장되어 있는지 확인하고 만약 그렇다면 테이블을 설정합니다. img 클래스가있는 모든 div에 대해 실행되어야하기 때문에 가능합니까? 언급의 pageshow는 QMobile의 이벤트이며, onpageshow 모든 브라우저에서 지원되지 않는 HTML5이기 때문에페이지로드시 JQuery 함수 실행

$(document).ready(function(){ 
    $(".img a").live('pageshow', function(event, ui) { 
     var item=$(this).attr('href'); 
     var action="check"; 
     jqxhr = $.post("webservice.php", { action: action, color: item }, function(data) { 
      var result=data.result; 
      if (result="saved") { 
       $("span", this).html("Saved"); 
       $(this).attr("href","saved"); 
      } 

     }, "json") 
     .error(function() {   
      alert("error: unable to contact web service"); 
     }); 
    }); 
}); 

다음은 HTML을

      <td> 
           <div class="img" style="background:#f8d3cf;"> 
            <a href="f8d3cf" rev="1" class="link"> 
             <span>Click to Save</span> 
             <em>Saved</em> 
            </a> 
            <div class="popup"> 
             <div class="holder"> 
              <div class="popup-img" style="background:#f8d3cf;"></div> 
              <div class="info"> 
               <h3>Desert Warmth</h3> 
               <strong class="num">70YR 56/190 <span>A0542</span></strong> 
              </div> 
             </div> 
            </div> 
           </div> 
          </td> 
+2

'.live()'는 더 이상 사용되지 않습니다. '.on()'이 선호되는 함수이다. – dnagirl

+0

'if (result = "saved")'가 대입이 아닌 경우 – dnagirl

+0

은 jqmobile입니까? – SpYk3HH

답변

0

을합니다. 대답은 'window.onload = function() {};'을 사용하는 것입니다. 해당 window.onload에있는 모든 것은 페이지로드시 처리됩니다. 다음은 window.onload를 사용한 방법입니다. 첫 번째 아약스 호출은 세션에서 cart_id를로드하거나 필요한 경우 cart_id를 작성합니다. ajax 호출이 완료되면 장바구니의 항목을 채우는 응용 프로그램이 호출됩니다.

window.onload = function() { 
    $j(".cartid").each(function() { 
     var self = $j(this); 

     jqxhr = $j.post("mycartid.php", function(data) { 
      self.html(data.cart_id); 
     }, "json").complete(function() { 

      $j("#cartitems").each(function() { 
       var self = $j(this); 
       jqxhr = $j.post("printitems.php", function(data) { 
        //var result=data.result; 
        self.html(data); 
       }, "html"); 

      }); 
     }); 
    }); 
}; 
0

마지막 줄에 '));' 해야한다 '});

$(document).ready(function(){ 
    $(".img a").live('pageshow', function(event, ui) { 
     var item=$(this).attr('href'); 
     var action="check"; 
     jqxhr = $.post("webservice.php", { action: action, color: item }, function(data) { 
      var result=data.result; 
      if (result="saved") { 
       $("span", this).html("Saved"); 
       $(this).attr("href","saved"); 
      } 

     }, "json") 
     .error(function() {   
      alert("error: unable to contact web service"); 
     }); 
    }); 
}); 
+0

오타를 수정해도 문제가 해결되지 않았지만 도움에 감사드립니다. – Codeguy007

관련 문제