2016-05-31 3 views
0

"변경"과 "클릭"을위한 두 개의 바인딩 함수를 만듭니다. .on()을 사용합니다. 그것은 내가 바꾸는 첫 번째 요소에서 작동하지만 두 번째 요소에서는 더 이상 작동하지 않습니다. "클릭"과 마찬가지로 .on()을 (selector)와 함께 래핑하려고 시도했습니다. each()는 루프를 원하지만 여전히 동일합니다. 누군가가 도와 주실 수 있습니까, 미안 해요, 아직이 일에 초보자입니다. 난 단지 그것이 변경 될 모든 입력 텍스트와 클릭 될 모든 링크에 대해 작동하도록하고 싶습니다. 아래는 제 코드입니다..on()을 어떻게 루프 할 수 있습니까?

여기에 html이 있습니다.

<table class="cart"> 
    <tbody> 
     <tr class="var"> 
      <th>Product</th> 
      <th class="quantity">QTY</th> 
      <th class="remove">&nbsp;</th> 
      <th class="price">Price</th> 
      <th class="total" colspan="2">Total</th> 
     </tr> 
     <tr class="val"> 
     <td> 
      <div class="sc-pi">{tag_productimage}</div> 
      <div class="sc-pn"> 
      <div class="sc-pn-box"> 
      <div class="sc-pn-name">{tag_productname}</div> 
      <div class="sc-pn-code">{tag_productcode}</div> 
      <div class="sc-pn-size">{tag_custom2}</div> 
      </div> 
      </div> 
     </td> 
     <td class="quantity"> 
      <div class="productitemcell"> 
      <input type="text" value="1" class="cartInputText"> 
      </div> 
      </td> 
     <td class="remove"> 
      <div class="productitemcell"><a href="#">Remove</a></div> 
     </td> 
     <td class="price">{tag_productextaxamount}</td> 
     <td class="total">{tag_producttotal}</td> 
     </tr> 

     </tbody> 
     </table> 


    <ul> 
    <li>Subtotal:<span>{tag_productgrandtotal}</span></li> 
    <li>Shipping Fee:<span>{tag_shippingtotal}</span></li> 
    <li>Promo Code:<span></span> </li> 
    <li><strong>Total:<span>{tag_invoicetotal}</span></strong></li> 
    </ul> 

<div id="warning" style="display:none;"> 
    <p>You can only purchase one product at a time.</p> 
</div> 

<div class="columns medium-4 pp"> 
<a id="catshopbuy"><img alt="" src="/images/btn-checkout_now.jpg" /></a> 
</div> 

여기에 표시된 태그는 무시하십시오. 이것은 내가 사용하고있는 CMS에서 생성됩니다. 기본적으로 저는화물 문제로 인해 고객이 한 번에 1 개 이상의 제품을 체크 아웃 할 수없는 장바구니를 만들고 있습니다. 따라서 여기에있는 제품의 수가 증가 할 수 있습니다. 고객은 제품 수량을 제거하거나 갱신합니다. 하나의 제품을 제거했을 때 괜찮 았지만 다른 제품을 제거했을 때 더 이상 작동하지 않습니다.

+0

html 도움이 될 것입니다. –

답변

1

함수를 사용하고 콜백합니다.

function callBack() { 
    var t = $(".sc-pn-size .productitemcell").length; 
    if (t > 1) { 
     $("a#catshopbuy").hide(); 
     $("#warning").show(); 
    } 
} 
//on click 
$("div.productitemcell a").on("click", callBack); 
//on change 
$("div.productitemcell input").bind("change", callBack); 
+0

죄송합니다. 작동하지 않았습니다. 여전히 동일합니다. 하나의 입력 상자에서 작동하지만 두 번째와 세 번째 상자에서는 작동하지 않습니다. – Mary

+0

@Mary Id는 고유해야합니다. html을 추가 할 수 있습니까? 이 요소들은'# catshopbuy, # warning'이 두 번 이상 나오나요? – RRK

관련 문제