简体   繁体   English

JavaScript将工具提示更改为大写

[英]JavaScript to Change Tooltip to Uppercase

Is there a method in JavaScript to change a tooltip/title attribute to all uppercase? JavaScript中是否有一种方法可以将工具提示/标题属性更改为全部大写? I know that tooltips can't be controlled through CSS, but I don't know anything about JavaScript. 我知道工具提示无法通过CSS进行控制,但是我对JavaScript一无所知。

I need to only change it on specific elements if possible. 如果可能,我只需要对特定元素进行更改。

Thank you for any information. 感谢您提供任何信息。

if you are using bootstrap, just apply "text-uppercase" to the tooltip element. 如果您使用的是引导程序,则只需在工具提示元素上应用“文本大写”即可。 It will automatically convert it to uppercase. 它将自动将其转换为大写。

您可以使用jQuery通过以下方式使用Javascript的.toUpperCase()

$('#SomeSelectorOfToolTip').attr('title', $('#SomeSelectorOfToolTip').text().toUpperCase())

Assuming you are talking about the default tooltip which appears upon mousing over an element with a title, you will have to do this by manipulating the title itself. 假设您正在谈论的是鼠标悬停在带有标题的元素上时出现的默认工具提示,则必须通过操作标题本身来做到这一点。 You can access the title property through the DOM with: 您可以使用以下方法通过DOM访问title属性:

var newTitle = document.getElementById("myElement")[0].title.toUpperCase
document.getElementById("myElement")[0].title = newTitle

Now this is, of course, inherently more difficult than simply changing the title itself, but if these are the criteria for what you are trying to accomplish it should work. 现在,这当然比简单地更改标题本身要困难得多,但是如果这些是您要实现的目标的标准,那么它应该起作用。

UPDATE 更新

It appears there may be a pure CSS solution actually. 看来实际上可能有一个纯CSS解决方案。 Take a look at the top answer to this question: Styling native tooltip from title="Tooltip text" 看看这个问题的最佳答案: 从title =“ Tooltip text”样式化本机工具提示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM