以下脚本运行良好。只是,现在我想添加更多按钮 和更多 ul 类。该脚本仅适用于一个按钮和一个 ul 类。
我已经尝试了很多东西,但现在我需要帮助。请看下图:
<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>
最佳答案
您可以使用 JQuery 的 .html() 设置元素的内容:
$('.imageData.clearfix').html(`<strong>This is the new element content</strong>`);
要附加新数据,请使用 JQuery 的 .append() :
$('.imageData.clearfix').append(`<li><a href="images/pride-w'14-8_large.jpg" data-background-color="#000000"></a></li>`)
关于javascript - 如何更改 jQuery 元素内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54993381/