未在javascript中加载简单动态div面板

未在javascript中加载简单动态div面板,javascript,css,asp.net,Javascript,Css,Asp.net,我试图学习如何用javascript创建和加载一个简单的动态面板 这是我的密码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/

我试图学习如何用javascript创建和加载一个简单的动态面板

这是我的密码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>

<!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 runat="server">
    <script type="text/javascript" language="javascript">
        function createQuestionPanel() {
            var div = '<div>top div</div>';
            return div;
        }

    </script>
</head>
<body onload=createQuestionPanel()>
<div id="d1" onclick=createQuestionPanel()></div>
</body>
</html>

函数createQuestionPanel(){
var div=‘顶部div’;
返回div;
}
在调试时(在Firebug上),面板加载良好。我尝试了各种可能的组合来调用该方法。但它没有加载。。如果是静态的,Div面板加载正常


我看到过使用style:visible功能显示/隐藏现有面板的建议。以及使用CSS。。我不想那样做。我只需要一个建议,这样做可能吗?

您已经定义了一个字符串。实际上,您永远不会将该字符串解释为DOM节点,也不会将结果添加到DOM中

试一试

$(document).append('top div');

函数createQuestionPanel(){
var div=document.createElement(“div”);
var textNode=document.createTextNode(“top div”);
附件子项(新内容);
文件.正文.附件(div);
}
将html更改为:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>

<!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 runat="server">
        <script type="text/javascript" language="javascript">
            function createQuestionPanel() {
                document.body.innerHTML += '<div>top div</div>';            
            }

        </script>
    </head>
    <body onload="createQuestionPanel()">

    </body>
</html>

函数createQuestionPanel(){
document.body.innerHTML+='top div';
}

他没有使用jquery。问题被标记为jquery,所以我想我可以使用它。
<script type="text/javascript" language="javascript">
    function createQuestionPanel() {
       var div = document.createElement("div");
       var textNode = document.createTextNode("top div");
       div.appendChild(newContent);
       document.body.appendChild(div);
    }
</script>
 <body onload=createQuestionPanel()>
  <div id="d1" onclick=createQuestionPanel()></div>
 </body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>

<!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 runat="server">
        <script type="text/javascript" language="javascript">
            function createQuestionPanel() {
                document.body.innerHTML += '<div>top div</div>';            
            }

        </script>
    </head>
    <body onload="createQuestionPanel()">

    </body>
</html>