<label id="Label1">
                <input type="checkbox"/>
            </label>
要求是获得用户选中这个checkbox之后的html,
则预期alert出来的结果是“<input type="checkbox" checked="checked"/>”
但是一般的jquery或者js这样写,得不到预期的结果alert($('#Label1')[0].innerHTML);
/////
alert($('#Label1').html());
动态

解决方案 »

  1.   

    厄。。要检测checkbox是否选中,用jquery的prop就可以
    但是我要的是获取Label1里面所有的标签最新的标签。。
    厄。。我表达有点问题。。
    Label1里面有很多标签内容,这个只是一个例子。
      

  2.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <title>无标题文档</title>
    </head><body><label id="Label1">
    <input type="checkbox"/>check item
    </label>
    <script type="text/javascript">
    jQuery(function($){
    $(":checkbox").click(function(){
    if($(this).is(':checked')){
    $(this).attr('checked','checked');
    }else{
    $(this).removeAttr('checked');
    }
    alert($('#Label1').html());
    });

    });
    </script>
    </body>
    </html>