jQuery大写单词定位器 [英] jQuery Uppercase word locator
本文介绍了jQuery大写单词定位器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找到在<p> </p>
之间用大写字母书写的超过4个字符的单词,并为其添加样式(例如斜体).
I need to locate words for more than 4 characters that are written between <p> </p>
in uppercase and add them a style (ex. italic).
我了解函数isUpperCase()
,但是不知道如何应用它来检查字符串是否超过4个字符.
I know about the function isUpperCase()
but don't know how to apply it to check if the string is more than 4 characters.
function isUpperCase( string ) {
(?)
}
谢谢.
推荐答案
var ps = [].slice.call(document.getElementsByTagName("p"))
ps.forEach(function (p) {
p.textContent.split(" ").forEach(function (word) {
if (word.length > 4 && word.toUpperCase() === word) {
// 4character UPPERCASE word
}
})
})
这篇关于jQuery大写单词定位器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文