3

There must be something special about the checked attribute of a checkbox either at the jQuery level or the DOM level. With this HTML:

<html>
    <body>
        <input id="cb" type="checkbox" />
    </body>
</html>

And this JavaScript:

$(function() {

    $("#cb").attr("checked","checked");
    alert("Expecting this HTML fragment to have a 'checked' attribute:\n\n"
          + $("body").html());

});

I'm not getting what I expect; if I use an attribute name besides "checked" it works as expected.

The reason I'm trying to get this to work is I need to get the HTML as it exists in a browser DOM and convert it to PDF, so users can get PDF versions of the page as it is as they're looking at it; it's manipulated heavily on the client side, so getting the correct HTML directly from the server is not an easy option.

Here's a working version of the above code: http://jsfiddle.net/pettys/qTfDP/2/

4

1 回答 1

4

更新到 jQuery 1.6。1.6/1.6.1 中发生了一些重大变化attr

于 2011-05-31T22:51:52.950 回答