在复选框上的div元素上加载jsp

时间:2013-03-08 17:31:32

标签: jquery ajax jsp checkbox

我需要在div元素上加载一个jsp页面,如果有任何checkboxes = check,如果未选中则隐藏div元素。到目前为止,我已经尝试了这个,但它根本不起作用!帮助!

JS:

    $(document).ready(function(){
$.each($("input[type=checkbox]:checked"),function(){
    $("verification").load("/selectionPage");
});

JSP:

<td class="cb" bgcolor='<c:out value="${summary.color}"></c:out>'><input
                        type="checkbox" value="">
                    </td>
                </tr>
            </c:forEach>
    </tbody>
</table>
       </div>
     <div id="verification"></div>

1 个答案:

答案 0 :(得分:1)

请阅读内联评论。

$(document).ready(function () {
    $("input[type=checkbox]").click(function () {

        //things you want to do when the checkbox is checked
        //like loading the jsp
        if ($(this).attr('checked') === 'checked') {

            //make sure the selector is correct. # for id, . for class etc.
            //also, /selectionPage or /selectionPage.jsp?
            //Basically, path resolver or hitting JSPs directly?
            $('#verification').load('/selectionPage.jsp', function () {
                console.log('done');
            });
        }

        //things you want to do when the checkbox is unchecked
        //like maybe clearing the div?
        else {
            $('#verification').html('');
        }
    });
}