Javascript 正在将img标记添加到已打开的img标记上
请原谅这个模糊的问题标题。我不太清楚怎么用这个词 基本上,我的问题源于一点jquery,其中在html中设置数据属性时,img标记会显示一些奇怪的行为,如下所示Javascript 正在将img标记添加到已打开的img标记上,javascript,jquery,html,Javascript,Jquery,Html,请原谅这个模糊的问题标题。我不太清楚怎么用这个词 基本上,我的问题源于一点jquery,其中在html中设置数据属性时,img标记会显示一些奇怪的行为,如下所示 <img src="images/gallery/ <img src="/images/gallery/bob.png" class="thumbnail" data="1"> " class="popupImage"> 这是您的问题:imgSrc=“/imag
<img src="images/gallery/
<img src="/images/gallery/bob.png" class="thumbnail" data="1">
" class="popupImage">
这是您的问题:
imgSrc=“/images/gallery/”++$(“a[data=”“+id+”]).html()代码>虽然我不确定你期望这行代码实际做什么。实际上问题在于你的php。将其更改为$item['image'],然后查看发生了什么在第一条语句中您分配给imgSrc
的是什么<我同意@RoryMcCrossan,imgSrc=“/images/gallery/”+$(“a[data=”“+id+”]).html()代码>返回标记内的所有内容,我认为这是完整的,仅获取数据值。或者更简单地说是imgSrc=“/images/gallery/”+id
@RoryMcCrossan和Dave(不能这样评价你)感谢你们两人的帮助,没有想过要改变这一点。当我想不出什么的时候,我的视力很差。所以,最好的答案还是你们两个。
<?php
$data = $db->query("SELECT * FROM `gallery_items` ORDER BY id ASC");
//display query results
?>
<br /><br />
<?php
foreach($data as $item)
{
echo "<a data='".$item['id']."' class='noStyle'>
<img src='/images/gallery/".$item['image']."' class='thumbnail' data='".$item['id']."'>
</a>";
}
if(count($data) < 1){
echo "<p style='text-align: center;'><br /><br />No results found</p>";
}
?>
<div class="image">
<button class="prev" data="unset"><</button>
<img src='' class="popupImage">
<button class="next" data="unset">></button>
</div>
$(".noStyle").click(function(){
loadPopup($(this).attr("data"));
});
offFocus();
function loadPopup(id){
imgSrc = "/images/gallery/"+$("a[data='"+id+"']").html();
$("div.background").fadeIn(400, function(){
$(".popupImage").attr("src", imgSrc);
$(".image").fadeIn(500);
reFocus();
setPrevNext($("button[data='"+id+"']"));
});
$(window).resize(function(){
reFocus();
});
function reFocus(){
$(".image").css({"left": (($(window).width()/2) - ($(".image").width()/2))+"px", "top": (($(window).height()/2) - ($(".image").height()/2))+"px"});
};
}/*close loadPopup */
function setPrevNext(buttonObj){
objects = $(".button");
firstObj = $(".button:first");
lastObj = $(".button:last");
prev = undefined;
next = undefined;
if(buttonObj.attr("data") == firstObj.attr("data"))
prev = lastObj;
else
prev = objects.eq(objects.index(buttonObj)-1);
if(buttonObj.attr("data") == lastObj.attr("data"))
next = firstObj;
else
next = objects.eq(objects.index(buttonObj)+1);
$(".prev").attr("data", prev.attr("data"));
$(".next").attr("data", next.attr("data"));
//next = buttonObj.next("button").attr("data");
//$(".next").attr("data", "next");
}
function offFocus() {
$(".background").click(function(){
$(".background").css({"display": "none"});
$(".image").css({"display": "none"});
});
};