在<body>标签之后插入DIV

Con*_*ion 4 javascript jquery internet-explorer-7

我有以下代码:

<script type="text/javascript">
    $(document).ready(function() {
        $('<div id="tools" style="text-align:right;float:right;"><input type="button" value="Print this page" onclick="window.print();return false;" /><input type="button" value="Save this page" onclick="go_saveas();return false;" /></div>').insertBefore('body');
    });
</script>
Run Code Online (Sandbox Code Playgroud)

基本上,我需要在<body>标签后面插入整个Div :

</head>
<body>
    <div id="tools"..
...
Run Code Online (Sandbox Code Playgroud)

哪个适用于Firefox,但在IE 7中不起作用,我需要更改什么来解决这个问题?

ick*_*fay 12

你正在使用insertBefore.那会试着把它放在head和之间body; 不是你想要的.试试prependTo.