2014-04-26 6 views
2

달성하고자하는 것 : 문서 (즉, 문서 1)를 클릭하면 사용자가 확인할 수 있도록 해당 문서의 오른쪽에있는 상자가 활성화됩니다. 그러나 현재 사용자가 문서 1을 클릭하면 모든 상자가 사용되도록 설정됩니다.단일 체크 상자 사용

예를 들어 문서 1을 사용하고 있었지만 각 문서 링크마다 이것을 원합니다. 누구든지 도와 줄 수 있습니까?

몇 가지 조사를했지만이 특정 것에 대한 수정 사항을 찾을 수 없습니다.

내 현재 코드 :

<!DOCTYPE html> 
<html> 

<head> 
<style> 
table, th, td 
{ 

border:1px solid black; 
border-collapse:collapse; 
} 
</style> 

<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
    $("a").click(function() { 
     $("input").removeAttr("disabled"); 
    }); 
}); 
</script> 

</head> 

<body> 

<form method="post" action="mailto:@null"> 
<table style="width:500px"> 
<tr> 

    <td><a href="https://null" target="_d1">Document 1</a> 
    <td><input type="checkbox" name="name1" value="D1" disabled></td> 
    </tr> 
<tr> 
    <td><a href="https://null" target="_d2">Document 2</a></td> 
    <td><input type="checkbox" name="name1" value="D2" disabled></td> 
    </tr> 
<tr> 
    <td><a href="https://null" target="_d3">Document 3</a></td> 
    <td><input type="checkbox" name="name1" value="D3" disabled></td> 
    </tr> 
<tr> 
    <td><a href="https://null" target="_d4">Document 4</a></td> 
    <td><input type="checkbox" name="name1" value="D4" disabled></td> 
    </tr> 
<tr> 
    <td><a href="https://null" target="_d5">Document 5</a></td> 
    <td><input type="checkbox" name="name1" value="D5" disabled></td> 
    </tr> 
<tr> 
    <td><a href="https://null" target="_d6">Document 6</a></td> 
    <td><input type="checkbox" name="policyAcknowledgement" value="D6" disabled></td> 
    </tr> 
</table> 

<input type="submit"> 
<input type="reset"> 
</form> 

</script> 
</body> 
</html> 
+0

사이드 노트, 당신은 길 잃은 것 같다''의 끝에 당신의 페이지. – j08691

+0

[JQuery - checkbox 사용/사용 중지] 가능한 복제본 (http://stackoverflow.com/questions/2330209/jquery-checkbox-enable-disable) – pennstatephil

답변

1

변경하여 jQuery를에 :

$("a").click(function (e) { 
    e.preventDefault(); 
    $(this).parent().next().find('input').removeAttr("disabled"); 
}); 

jsFiddle example

+0

완벽한. 엄청 고마워. –

+0

'prop ('disabled', false)'대신에'removeAttr ('disabled')'를 사용하는 이유가 있습니까? 진정으로 당신이 선택한 접근 방식을 비판하지 않고 궁금해합니다. –

+0

@DavidThomas - 좋은 질문입니다. 아니, 사실 아무 생각도하지 않았다. 일반적으로 나는'prop ('disabled', false)'를 할 것이지만, 나는 OP의 원래 코드를 다시 사용했다. – j08691

관련 문제