【发布时间】:2011-09-11 10:20:36
【问题描述】:
我想根据我在图像滑块上开发的点击动态更改标题。我已经尝试通过警报检查我的代码,每次单击警报都会显示一个不同的名称。但是当我尝试 append() 或 html() 时,它会停留在第一个图片名称上。
var src = $('#slides img').attr('src');
$("#image").click(function(){
$("#pic-title").html(src); //this shows the first images' name and never changes.
//$("#pic-title").append(src); //this shows the first images' name and adds on each click, but stays the same name and never changes.
});
<div id="pic-title"></div>
我想更改图片名称,不要重复。
有什么建议吗?
谢谢
【问题讨论】:
-
你能把这个引用的html也加进去吗?
-
我想这就是你所说的 html 的意思?我添加了输出标题名称时应该引用的div标签。
-
你为什么使用图像src attr,为什么不使用rel、alt或title?
-
这只是一个例子来说明我的观点
-
我想很多人确实将文件名用作一种标题,只是好奇。
标签: jquery html image dynamic append