2014-06-16 2 views
-1

아래의 코드에서 귀하의 전문 지식이 필요합니다. 체크 박스를 체크하고 클릭 버튼을 삭제하는 경우JavaScript : 체크 박스가 선택된 상태에서 모든 그리드 행을 숨기려면 버튼 클릭

<html> 
    <head> 
    <script> 
    function delrow() { 

     document.getElementById("db_grid_row1").style.display = 'none'; 
     document.getElementById("db_grid_row2").style.display = 'none'; 
     document.getElementById("db_grid_row3").style.display = 'none'; 
     document.getElementById("db_grid_row4").style.display = 'none'; 

    } 
    </script> 
    </head> 
    <body> 
    <form action="rowhide_action.php" method="post" name="save_form"> 

    <input type="button" value="Delete" onClick="delrow();"></input> 


    <table border="1"> 
    <thead> 
    <tr> 
    <th>#</th> 
    <th>Databases</th> 
    </tr> 
    </thead> 

    <tbody id="db_grid"> 

    <tr id="db_grid_row1"> 
    <td><input type="checkbox" name="cbox[]" value="1" ></input></td> 
    <td><input type="text" name="db[]" value="Oracle"></input></td> 
    <td><input type="hidden" name="modeflag[]" value="S" ></input></td> 
    </tr> 

    <tr id="db_grid_row2"> 
    <td><input type="checkbox" name="cbox[]" value="1"></input></td> 
    <td><input type="text" name="db[]" value="MySQL"></input></td> 
    <td><input type="hidden" name="modeflag[]" value="S"></input></td> 
    </tr> 

    <tr id="db_grid_row3"> 
    <td><input type="checkbox" name="cbox[]" value="1"></td> 
    <td><input type="text" name="db[]" value="Cassandra"></input></td> 
    <td><input type="hidden" name="modeflag[]" value="S"></input></td> 
    </tr> 

    <tr id="db_grid_row4"> 
    <td><input type="checkbox" name="cbox[]" value="1"></input></td> 
    <td><input type="text" name="db[]" value="Mongo"> </input></td> 
    <td><input type="hidden" name="modeflag[]" value="S"></input></td> 
    </tr> 

    </tbody> 
    </table> 
    </br> 
    <input type="submit" value="Save"></input></br></br> 
    </form> 
    </body> 
    </html> 

, 나는 (1) 행이 가지고있는 체크 박스를 숨겨 싶어요. (2) 숨김 행의 요소 modeflag [] value = "D"변경

도와주세요. 미리 감사드립니다. jQuery로

+0

수 당신 jquery, 또는 순수한 js를 사용합니까? – webkit

+0

JS 또는 Jquery가 괜찮습니다. –

답변

1

그것은 다음과 같이 진행됩니다

$(function() { 
    $("#del").on('click', delrow); 
}); 
function delrow() { 
    var checks = $("input[type=checkbox]:checked"); 
    checks.parent().parent().hide(); 
} 

DEMO

통지 내가 .. 당신은 어떤 질문이 있으면 알려 주시기 자바 스크립트로 html 요소에서 이벤트를 제거

+0

안녕하세요 webkit, 작동하지 않습니다. .js 파일을 포함해야합니까? 또한 내 # 2 질문에 대답 해 주시겠습니까? "요소 모드 플래그 변경 [] 값 ="숨겨진 행의 D "" –

+0

안녕하세요 webkit, 고마워요. 잘 작동하고 jquery-1.8.3.min.js 파일을 추가했습니다. # 2 질문에 대답 해 주시겠습니까? "요소 모드 플래그 변경 [] 값 ="숨겨진 행의 "D" –

+0

@PrakashRaj # 2와 (과) 여전히 도움이 필요합니까? – webkit