标题/Alt 属性未显示
我有一个脚本,它从跨度中获取 alt,将其用作图像的 src。获取该范围的类并将其传输到 img,最后获取该范围的文本并将其用作 alt 或标题。由于某种原因,替代/标题部分不起作用。即使我指定每个图像都会有的静态标题/替代品,它仍然不会显示。
我需要在这些翻译中保留 3 条信息:类、名称和 url。 Alt/title 将是一个有用的属性,用于存储名称部分。 (因为 img 标签没有名称空间)从技术上讲我可以使用 id,但这些图像在整个会话过程中被克隆。
var $this = $(this);
var src = $this.attr('alt');
var Name = $this.val();
var Type = $(this).attr('class');
$(target).parent().after($('<div class="Packet"></div>').append('<img src="'+ src +'" class="Border '+ Type +'" title="some title" />'));
I have a script that takes the alt from a span, uses it as an src for an image. Takes the class of that span and transfers it to the img, and finally, takes the text of the span and uses it as an alt or title. For some reason the alt/title part isn't working. Even if i specify a static title/alt that each image would then have, it still doesn't show up.
I have 3 pieces of information that i need to preserve across these translations, class, name, and url. Alt/title would be a useful attribute with which to store the name portion. (since img tags don't have name space) I could technically use id, but these images are being cloned throughout the session.
var $this = $(this);
var src = $this.attr('alt');
var Name = $this.val();
var Type = $(this).attr('class');
$(target).parent().after($('<div class="Packet"></div>').append('<img src="'+ src +'" class="Border '+ Type +'" title="some title" />'));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
val()
方法仅适用于输入字段获取“value”属性。如果您想获取范围内的文本,请使用text()
或html()
。前一个选项忽略 html 标签。另外,在通过 jQuery 创建元素时,请考虑将属性传递给第二个参数:
The
val()
method is only applicable to input fields to obtain the "value" attribute. If you want to get the text inside the span then usetext()
orhtml()
. The former option ignores html tags.Also, consider passing attributes to the second parameter when creating elements via jQuery: