查找字体大小大于指定的元素
我试图定义一个 JQuery 语句来查找 font-size
大于(或小于)输入值的元素。
可能的输入值:
"12px"
"14pt"
"120%"
and so on...
我的第一个方法更像是一个草案,因为它不能以这种方式工作。但也许您有如何实现解决方案的想法。这是我到目前为止所拥有的(输入值来自其他地方并且是可变的):
$('*').filter(function() {
return $(this).css('font-size') > '12px';
})
有人吗?
更新
我被要求解释为什么我需要这样的东西。我正在 Java 中使用 Selenium2 编写一个 API,它能够以更简单、更可靠的方式查找元素并与它们交互。这个函数将允许我编写类似 browser.find().titleElements()
的代码,它选择所有 h1
、h2
,... 标签,但也包括字体大小比页面上的平均文本更大的元素。
该框架还将提供选择视觉上彼此接近或在特定方向上的元素的功能:
HtmlElement nameLabel = browser.find().labelElement("name");
HtmlElement nameInput = browser.find().closestInputElement(nameLabel);
nameInput.below("tos").select();
I am trying to define a JQuery statement for finding elements which have a greater (or lesser respectively) font-size
than an input value.
Possible input values:
"12px"
"14pt"
"120%"
and so on...
My first approach is more of a draft because it cannot work this way. But maybe you have ideas how to achieve a solution. Here is what i have so far (the input value comes from elsewhere and is variable):
$('*').filter(function() {
return $(this).css('font-size') > '12px';
})
Anyone?
Update
I was asked to explain why i would need something like this. I am writing an API using Selenium2 in Java, which is able to find elements and interact with them in an easier and more reliable way. This function will allow me to write code like browser.find().titleElements()
which selects all h1
, h2
,... tags, but also elements which have a greater font-size than the average text on the page.
The framework will also provide functions to select elements which are visually close to each other or in a specific direction:
HtmlElement nameLabel = browser.find().labelElement("name");
HtmlElement nameInput = browser.find().closestInputElement(nameLabel);
nameInput.below("tos").select();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我制作了一个小插件,能够获取您要求的所有参数。不知道它有多准确,因为我是匆忙做的。如果你的 DPI 不是 72,
pt
肯定会关闭。插件代码
用法
你可以在这个 jsFiddle 上的测试用例。
转换器帮助优化的额外功劳。
I made a small plugin that's able to take all the parameters you ask for. No idea how accurate it is since I made it in a rush.
pt
will definately be off if your DPI is anything other than 72.Plugin code
Usage
You can try it out in this test case on jsFiddle.
Additional credits to converter for helping out with the optimization.
你需要解析字体大小...
尝试这种方式..
you need to parse the font size...
try this way..
您可以使用 parseint 这样的东西:
并这样调用它:
You can use parseint so something like this:
and call it like this: