简体   繁体   English

使用jQuery append()添加html元素后页面源出现问题

[英]Issue with page source after Adding html elements using jQuery append()

I am new to jQuery.I used jQuery append() to add HTML elements.After that viewing the page sorce that elements not displayed,but they already added and shown in webpage. 我是jQuery的新手,我使用jQuery append()添加HTML元素。此后,查看页面后,没有显示元素,但它们已经添加并显示在网页中。

Code: 码:

<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="js/libs/jquery/jquery.js" type="text/javascript"></script>
    </head>
    <body>      
        <div id="button-div">
            <button id="test-btn">
                Click Me
            </button>
        </div>
        <script>
            $('#test-btn').click(function (){
                $('#button-div').append("<div>This is sample text</div>");
            });
        </script>
    </body>
</html>

Actualy i want to a some elements to add html webpage and save that newly added elements to database. 实际上,我想要一些元素来添加html网页并将新添加的元素保存到数据库中。

then I used Jquery for collect the content,They it shown empty result.that the real issue. 然后我用Jquery收集内容,它们显示为空结果。那是真正的问题。

You have to use the DOM inspector. 您必须使用DOM检查器。 Viewing page source will only load static HTML, since your javascript execution added the dynamic HTML, it won't be visible that way. 查看页面源将仅加载静态HTML,因为您的javascript执行中添加了动态HTML,因此它不会以这种方式显示。

Your elements will not appear in the sourcecode. 您的元素不会出现在源代码中。 You can see what happened if you use the element inspector. 您可以查看使用元素检查器发生的情况。 In Chrome on windows you can show using F12 key or cmd+alt+i on mac osx. 在Windows上的Chrome中,您可以在Mac OS X上使用F12键或cmd + alt + i进行显示。

页面源仅显示页面加载时添加的html,可以使用Firebug Inspect或chrome inspector查看通过javascript或jquery页面加载后添加的html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM