将页面上的所有文本转换为小写
我正在寻找一种将页面上存在的所有文本转换为小写的方法。我正在阅读一篇评论,不幸的是该人以全部大写形式发布。我尝试阅读,但所有大写文本都很难阅读,更不用说它被认为在网络上大喊大叫。
我知道 javascript 有诸如 string.toLowerCase()
& 之类的方法string.replace
但我不明白。
因此,寻找某种 JavaScript 书签,将已加载的 html 页面上的所有文本转换为小写字母。
[编辑]
找到解决方案,这里的javascript代码更改整个页面的css样式text-transform: lowercase
:
var styleElement = document.createElement("style");
styleElement.type = "text/css";
if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = "* { text-transform: lowercase }";
} else {
styleElement.appendChild(document.createTextNode("* { text-transform: lowercase; }"));
}
document.getElementsByTagName("head")[0].appendChild(styleElement);
I am looking for a method that transforms all text present on the page into LowerCase. I was reading an review and unfortunatelly the person has posted in all uppercase. I tried to read but all uppercase text is harder to read, not to mention it is considered shouting on the web.
I know javascript have methods such as string.toLowerCase()
& string.replace
But I can't figure it out.
so looking for some kind of JavaScript bookmarklet that converts all text into LowerCase on a already loeaded html page.
[Edit]
Found the solution, here javascript code to change the css style text-transform: lowercase
for entire page:
var styleElement = document.createElement("style");
styleElement.type = "text/css";
if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = "* { text-transform: lowercase }";
} else {
styleElement.appendChild(document.createTextNode("* { text-transform: lowercase; }"));
}
document.getElementsByTagName("head")[0].appendChild(styleElement);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你只是想将 html 文本更改为小写,你可以使用 css 来完成。
那行得通吗?
If you are simply wanting to change html text to lowercase, you could do it with css.
Would that work?
您可以设置一个小书签,而不是将所有内容都转换为小写,单击该小书签将记录下一次单击的位置。从该位置,您可以使用
document.elementFromPoint(x, y)
方法来获取实际的 dom 节点。该 dom 节点可能是标记或
但可能有点矫枉过正了!
Instead of turning everything to lowercase, you could set up a bookmarklet, which when clicked, will record the position of your next click. From the position you can use the
document.elementFromPoint(x, y)
method to get the actual dom node. This dom node will probably be a<p>
tag or a<div>
tag. Do whatever you want now!May be an overkill though!