日期:2014-05-16  浏览次数:20368 次

为什么以下代码不能动态插入span节点?
JScript code
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>插入节点</title>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript">
        var p3=document.createElement("span");
        p3.text("p3");
        p3.insertAfter("div.container");

    </script>
</head>
<body>
<div class="container">
    <div class="p1">p1<br/></div>
    <div class="p2">p2<br/></div>

</div>

</body>
</html>


------解决方案--------------------
JScript code
        $(function () {
            var p3 =$( document.createElement("span"))
            p3.text("p3");
            p3.insertAfter("div.container");
        });