2015-01-29 1 views
0

이름이 같은 경우 별도의 줄에 확인란의 관련 텍스트를 가져 오는 문제의 해결책입니다.checkBox를 선택하고 별도의 줄에 연결된 텍스트 가져 오기

HTML 코드 -

<p><input name="SiteLayoutDesign" value="5" type="checkbox"> I do not need any unique graphics designed (0 Hours)</p> 
<p><input name="SiteLayoutDesign" value="6" type="checkbox"> I will supply images (0 Hours)</p> 
<p><input name="SiteLayoutDesign" value="7" type="checkbox"> I have a template but it needs minor customization (0 Hours)</p> 
<p><input name="SiteLayoutDesign" value="8" type="checkbox"> I need a template customized (0 Hours)</p> 
<p><input name="SiteLayoutDesign" value="9" type="checkbox"> I would like a custom design created for my site (0 Hours)</p> 

jQuery를 코드 -

$(document).ready(function(){ 
    $('input').click(function(){ 
     var $check = $('input[type=checkbox]:checked'); 
     $check.each(function(){ 
      var id = $(this).val(); 
      var did = $('input[type=checkbox][value='+id+']:checked').closest('p').text(); 

     }); 
    }); 
}); 

은 체크 박스의 값에 대한 변수를 저장에게 관련 텍스트를했다.

+0

당신은 레이블에 텍스트를 넣어야합니다. 그게 처음에 무엇을 위해. U 다음으로 csn이'next() '를 사용하여 목표를 지정하십시오. – DarkBee

답변

0
function SelectallColorsForStyle(e, eval) { 
     if (e.checked) { 
      $(":checkbox[value=" + eval + "]").prop("checked", e.checked); 

      if (!$('input.checkboxselection[type=checkbox]:not(:checked)').length) 
       $("#CHK_STY_ALL").prop("checked", true); 

      if (!$('input.chk_clr_ind[type=checkbox]:not(:checked)').length) 
       $("#chk_clr_sel_all").prop("checked", true); 
     } 
     else { 
      $(":checkbox[value=" + eval + "]").attr('checked', false); 
      $("#CHK_STY_ALL").attr("checked", false); 
      $("#chk_clr_sel_all").attr("checked", false); 
     } 
    } 

위의 코드는 동일한 값으로 실행됩니다. 귀하의 요구 사항에 따라 이름을 변경할 수 있습니다.

Refference DEMO

+0

답변을 주시면 코드에 어떤 내용이 있는지 설명해보십시오. –

0
First thing I dont understand why you are using '$' for javascript variable declaration and this is wrong. 

    Next thing you have a bad logic. 

    try this: 

    <script type="text/javascript"> 
     $(document).ready(function(){ 
     $('input').click(function(){ // whenever an input tag is clicked not sure why you want to run this for all inputs like text, textarea etc 
      $('input[type=checkbox]').each(function(){//for every input of kind checkbox 
       if($(this).is(':checked')){//check if this instance of check box is checked 
       var id = $(this).val();//if true get the value of this checkbox 
          var did = $('input[type=checkbox][value='+id+']:checked').closest('p').innerhtml();//for matching input type checkbox and value get the closest P and get its innerhtml. 
//warning: here you will get 2 closest P's for every checkbox except for first 
    } 

      }); 
     }); 
    }); 
     </script> 

위의 스크립트는 내가 확실 해요 출력은 당신이 원하는 것과 동일 생산하고 있습니다. 그러나 그것은 확실히 당신이 교정을하고 당신이 시도하는 것을 달성하는 데 도움이 될 것입니다

+0

, 협조 해 주셔서 감사합니다. 코드의 일부만 제공합니다. 라디오 버튼도 있습니다. 버튼 중 하나를 클릭 할 때 계산이 필요합니다. 나는 왜 당신이 내 논리가 나쁘다고 말했다고 말하고 싶습니까 ??? 나는 왜 당신이 이것을 말하는지 잘 모르겠다. 그렇다면 나는 좋은 것을해야만한다. – MuteX

+0

의미있는 나쁜 논리 당신이 무언가를 코딩하고 예를 들어서 .html()을 사용하여 P의 내부 텍스트를 얻으려는 경우에 다른 것을 기대하고 있다는 의미에서 잘못된 논리 –

관련 문제