如何更改jQuery元素内容

问题描述 投票:2回答:1

以下脚本工作正常。只是,现在我想添加更多按钮和更多ul类。该脚本仅使用一个按钮和一个ul类。

我尝试了很多东西,但现在我需要帮助。请看下面的图片:

The script (demo site)

<body>
        <header>
            Testing
        </header>

            <input type="button" value="Open 1" id="openOne" />
            <input type="button" value="Open 2" id="openTwo" />

    <ul class="imageDataOne clearfix">
        <li><a href="images/img-part-1-1.jpg" data-background-color="#000000"></a></li>
        <li><a href="images/img-part-1-2.jpg" data-background-color="#000000"></a></li>
    </ul>

    <ul class="imageDataTwo clearfix">
        <li><a href="images/img-part-2-1.jpg" data-background-color="#000000"></a></li>
        <li><a href="images/img-part-2-2.jpg" data-background-color="#000000"></a></li>
    </ul>

    <script type="text/javascript">
        $(document).ready(function() {

            //      v         Here is the problem                                 
            $('.imageDataOne a').apImageFullscreen({
                imageZoom:{},
            });

            $('#openOne').click(function() {
                $('.imageDataOne a:first')
                    .apImageFullscreen('option', 'enableScreenfull', $('#use-fullscreen').is(':checked'))
                    .apImageFullscreen('open', 0);
            });

            $('#openTwo').click(function() {
                $('.imageDataTwo a:first')
                    .apImageFullscreen('option', 'enableScreenfull', $('#use-fullscreen').is(':checked'))
                    .apImageFullscreen('open', 0);
            });             


        });

    </script>
</body>
javascript jquery element var
1个回答
0
投票

您可以使用JQuery qazxsw poi设置元素的内容:

.html()

要附加新数据,请使用JQuery的$('.imageData.clearfix').html(`<strong>This is the new element content</strong>`);

.append()
© www.soinside.com 2019 - 2024. All rights reserved.