2012-03-23 2 views
1
<html> 
    <head> 
    <link type="text/css" rel="stylesheet" `href="file:///C:/Users/Documents/style.css" /> 
    <script type="text/javascript" src="file:///C:/Users/Documents/jquery-`1.7.1.js"></script> 
    <script type="text/javascript" `src="file:///C:/Users/Documents/jquery.tablesorter.js"></script> 

<script type="text/javascript"> 
$(function() { 

    $('#hpTable input').click(function() 
    { 
     var $input = $(this); 
     var $inputTD = $input.closest("tr"); 
     if($input.prop('checked')) 
     { 
      var code = $inputTD.children('#name').attr("value"); 
      alert("code " + code); 

      //var $numberList = $('#popFields select:option[value=' + code + ']').attr("selected", "selected"); 
      //$('#hpTable select:option[value=' + code + ']').attr("selected", "selected"); 
      //$numberList.val($inputTD.children('#numberList eq[value=' + code + ']').attr("selected", "selected")); 
      //$numberList.eq(code).attr('selected', 'selected'); 
      //$inputTD.find('#numberList option').eq(code).attr('selected', 'selected'); 
      $inputTD.closet('select option').eq('3').attr('selected', true); 
     } 
    }); 
}); 

</script> 
</head> 
<body> 
<table id="popFields"> 
<thead></thead> 
<tbody> 
    <tr><td> 
     <select id="numberList"> 
      <option value="1" selected>one</option> 
      <option value="2">two</option> 
      <option value="3">three</option> 
     </select> 
    </td></tr> 
</tbody> 
</table> 
<br> 
<table id="hpTable" cellpadding="5" width="100%" style="table-layout:fixed" class="tablesorter"> 
<thead><tr> 
     <th width="9%"></th> 
     <th width="9%">Date</th> 
     <th width="9%">Name</th> 
     <th>File</th> 
    </tr> 
</thead> 
<tbody> 
    <tr> 
     <td><input type="checkbox"/></td> 
     <td id="date">3/3/2003</td> 
     <td id="name" value="3">Bob</td> 
     <td id="file">filename.doc</td> 
    </tr> 
</tbody> 
</table> 
</body> 
</html> 

안녕하세요, 다시 ... 여기 테이블 두 개가 있습니다. 사용자가 체크 박스를 클릭하면 드롭 다운 목록에 값을 표시하고 싶습니다. 나는 많은 일을 시도한 것 같지만 지금은 정말 좌절하고 있습니다. 나는 정말 어떤 도움을 주셔서 감사합니다!테이블에서 옵션 선택이 변경되지 않습니다.

그런데 아무나 좋은 jQuery 책을 추천 할 수 있습니까? 감사!

+0

[학습 jQu ery, Third Edition] (http://www.amazon.com/Learning-jQuery-Third-Jonathan-Chaffer/dp/1849516545) – shaunsantacruz

+0

코드를 읽을 수 있도록 다시 포맷하십시오. – shaunsantacruz

+0

귀하의 HTML은 길입니다. 테이블에 태그가 없습니다. '