gpt4 book ai didi

javascript - 如何在jquery中获取具有唯一编号的div的ID?

转载 作者:行者123 更新时间:2023-12-03 05:06:58 26 4
gpt4 key购买 nike

我在我的应用程序中使用 jquery slider 。隐藏的输入类型有一些图像 url 路径。我想要得到“

   img-paths- <?php echo $omsg_id; ?>

” $omsg_id 值写入 var image_path_id = "#img-paths-"+$(this).data('id');

当我在 fire bug 中打印控制台时,输出是#img-paths-undefined

如何解决?

    <div class="post-image">
<?php $imagePathArray = explode(',',$uploads); ?>
<input id="img-paths-<?php echo $omsg_id; ?>" type="hidden" value="<?php echo htmlentities(json_encode($imagePathArray)); ?>" />
<div id="gallery7-<?php echo $omsg_id; ?>" ></div>
<script>
$(function(e) {

var image_path_id = "#img-paths-"+$(this).data('id');
var show_gallery_id = "#gallery7-"+$(this).data('id');
console.log(show_gallery_id);
console.log(image_path_id);

$(show_gallery_id).imagesGrid({
images:$.parseJSON($(image_path_id).val()),
align: true,
getViewAllText: function(imgsCount) { return 'View all' }
});

});

</script>

<!--<img src="<?php //echo $contentimage; ?>" class="image show-in-modal" alt="image post">-->
<p><?php echo $message; ?></p>
</div>

最佳答案

this 引用 window 对象,因此 $(this).data('id') 将不会返回所需的数据。

您可以在脚本中直接使用$omsg_id

var image_path_id = "#img-paths-<?php echo $omsg_id; ?>";
var show_gallery_id = "#gallery7-<?php echo $omsg_id; ?>";

关于javascript - 如何在jquery中获取具有唯一编号的div的ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41974418/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com