에 여러 값을 추가 :간단한 jQuery를 다음 소스 사용하여 텍스트 상자
- 에
<div id="addons"> <div class="addon"> <span class="title"><input type="checkbox" value="addon_1" name="Item 1 title"></span> <span class="cost">$<em>20</em></span> </div> <div class="addon"> <span class="title"><input type="checkbox" value="addon_2" name="Item 2 title"></span> <span class="cost">$<em>45</em></span> </div> <div class="hidden" id="summaries"> <input name="addons_titles" id="addons_titles" type="text" value=""><!-- on checkbox click, add item titles --> <input name="addons_cost" id="addons_cost" type="text" value=""><!-- on checkbox click, total item cost --> </div> </div><!-- end addons -->
내가 노력하고있어에서 제목 요약 ".title 입력 .addon 을 [이름]" ~ 입력 #addons_titles (각 제목은 파이프 문자로 구분됨 - 예 : "Item 1 title | Item 2 title")
- 및 총 항목 비용은 ".addon .cost이 그들을 "입력 #의 addons_cost 에
어떤 생각 많이 감사합니다 - 감사합니다!
'result = new Array();'및 '$ ('addon_titles ') .val (result.join ('| '));'를 루프 내부에 배치하십시오. 매우 공정한 비교가 아닙니다 :) 이점은 단일 시작 비용 때문입니다.concat 루프에는 val이 설정되어 있지 않습니다. 어쨌든, 특별한 경우에 소비 된 시간의 대다수는 선택자에 있습니다. 나는 셀렉터의 일부가 얼마나 큰지를 보여주기 위해 샘플 케이스를 게시했다. +1 날이 다시 설정되면 (그리고 투표 할 수 있습니다!) 더 깊이 파고 성능에 대한 자세한 내용을 보려면 많은 프로그래머가 더 이상 신경 쓰지 마세요 –