2012-07-25 3 views
0

일부 html을 가져와 "제품 추가"를 클릭 할 때마다 반복 할 jQuery 스크립트가 있습니다. 이 제품은 겉으로보기에는 잘 작동하지만 여러 제품 (동일한 제품)을 추가 할 수 있다는 것을 알게되었습니다. 따라서 라디오 버튼이 간섭합니다. 고유 한 라디오 이름 속성이 필요합니다. 나는 이것을 어디서 시작해야할지조차 모르겠다. 나는 카운터를 가지고 현재 이름에 그것을 추가 할 수 있다고 생각한다. 사전에 도움을 청한다. 여기 라디오 버튼에 고유 이름 추가

는 HTML의 예입니다

<div id="product-container" class="product-container" style="display:none"> 
<div class="product-wrapper white-rounded"> 
    <div id="product-name" style="display:none"></div> 
     <h4>Example Product 1</h4> 
     <span class="align-right"> 
      <input name="select2" type="radio"><strong style="margin-right:20px">Option 1</strong> 
      <input name="select2" type="radio"><strong>Option 2</strong> 
     </span> 
     <div class="remove float-right"> 
      <a href="#"><div class="img-remove"></div>Remove</a> 
     </div> 
     <div class="clear"></div> 

    </div> 
</div> 

그리고, 여기에 코드를 잡고 앵커 포인트에서 그것을 밖으로 뱉어 JQuery와 있습니다 :

$('.add-product').click(function() { 
     if (Products < 4 || (Products == 4 && Products2 == 1)) { 
     //Store html contents in Variable 
      var thisProduct = $('#product-container').html() 
     //Add account html to account center anchor point 
      $('.add-product').before(thisProduct) 
      $('#product-name').text(productName) 
     //Add one more Product Count 
      Products++ 
     //Add Product Count value to hidden Input Field, then manually trigger the change event. 
      $('.product-count').val(Products).change() 
     //Scroll to top of page after account is added 
      $('html, body').animate({scrollTop:0}, 'slow'); 
     } 

     else { 
      alert('HALP!'); 
     } 
    }); 
+0

코드뿐만 아니라 ID를 복제하고 그건 것 같습니다 아니, 아니. – j08691

+0

글쎄, ID가있는 컨테이너 내부의 html을 가져 와서 실제 마크 업에서이를 반복하지 않습니다. 적어도 나는 그렇게 생각하지 않는다. .. 그러나 나는 두 번 점검 할 것이다. 감사. – TurboSupra

답변

1

은 당신이해야 할 노력이 이름의 증가분?

이렇게하면 결코 같은 이름을 반복하지 않습니다!

+0

그건 정확히 내가 생각하고있는 것인데, 나는 jQuery와 함께 최고가 아니며 이것을 달성하는 방법을 잘 모르고있다. – TurboSupra

0

가장 빠른 그것은에 allways 고유 한 것, 이것은 단지 카운트 실행을하고 ID 또는 클래스에 그를 추가하는 것입니다 해결하기 위해 그 방법이었다

var un1 = 0; 

for(yourloop){ 
    $("#whatever").append("idname"+un1); 
    un1++; 
} 
+0

이것은 의미가 있지만, 'un1'을 name = "whatever"필드에 추가해야합니다. 나는 이것을 아마도 몹시 설명 할 것입니다. 이 html 콘텐츠를 한 번 더 추가하면 라디오 버튼을 선택하면 다른 모든 라디오 버튼이 선택 해제됩니다. 따라서 이름 필드를 모두 고유하게 변경해야합니다. – TurboSupra

관련 문제