Rails - 添加 HTML 属性而不设置值 [英] Rails - Add HTML attribute without setting a value

查看:38
本文介绍了Rails - 添加 HTML 属性而不设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 image_tag 并指定一个没有设置任何值的数据属性.我正在尝试添加数据工具提示,以与 Foundation 5 工具提示一起使用.似乎如果实际设置了任何值,Foundation 每次都使用相同的工具提示文本并忽略该元素的标题属性(所以每个工具提示都会说你悬停在第一个上的是什么......这似乎有问题并且基金会本身也是)

I'm trying to create an image_tag and specify a data- attribute that does not have any value set to it. I'm trying to add data-tooltip, for use with Foundation 5 tooltips. It seems that if any value is actually set to this, Foundation uses the same tooltip text every time and ignores the title attribute of that element (so every tooltip will say whatever the first one you hovered on was... which seems buggy in and of itself on Foundation's part also)

这是我需要生成的:

<img src="[whatever]" title="My Tooltip" data-tooltip />

这对我不起作用:

<img src="[whatever]" title="My Tooltip" data-tooltip="[insert anything here]" />

我尝试了许多不同的组合,并阅读了文档,但似乎无论我将什么作为值,它最终都会像 data-tooltip="null"、true、false 或任何一样生成它我通过的字符串.

I have tried a number of different combinations, and read documentation, but it seems no matter what I put as the value, it ends up generating it like data-tooltip="null", or true, or false, or any string I pass.

image_tag(my_image, class: 'has-tip', title: "My Title Here", data: { tooltip: true })

推荐答案

尝试传入空字符串如下:

Try to pass in empty string as follows:

image_tag(my_image, class: 'has-tip', title: "My Title Here", data: { tooltip: "" })

这篇关于Rails - 添加 HTML 属性而不设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆