YUI3 JavaScript:获取占位符文本的 CSS
我正在编写一些 JavaScript 来在没有占位符文本的浏览器中实现占位符文本。
我已使用以下样式规则成功地在 Chrome 9 和 Fx 4b11 中设置了占位符文本的样式:
::-webkit-input-placeholder { color: #969696 !important; }
input:-moz-placeholder { color: #969696 !important; }
现在,我希望 JavaScript 从不理解这些规则的浏览器中的样式表中检索此数据,以便我可以手动设置占位符文本的样式。
有谁知道如何在 YUI3 中做到这一点?我尝试过:
YUI().use('node',function(Y) {
var phColor = Y.all('::-webkit-input-placeholder').getStyle('color');
});
不幸的是,这只是返回: “未定义:未绑定到任何节点 { _query="input::-webkit-input-placeholder", _nodes=}"
有人知道我该怎么做吗?或者如果可能的话?
I'm writing some JavaScript to implement placeholder text in browsers that don't have it.
I've successfully styled the placeholder text in Chrome 9 and Fx 4b11 using the following style rules:
::-webkit-input-placeholder { color: #969696 !important; }
input:-moz-placeholder { color: #969696 !important; }
Now I want my JavaScript to retrieve this data from the stylesheet in browsers that don't understand those rules so I can manually style the placeholder text.
Does anyone know how I can do that in YUI3? I tried:
YUI().use('node',function(Y) {
var phColor = Y.all('::-webkit-input-placeholder').getStyle('color');
});
Unfortunately this just returns:
"undefined: not bound to any nodes { _query="input::-webkit-input-placeholder", _nodes=}"
Anyone know how I can do this? Or if it's possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不打算专门使用 YUI(或者愿意从插件中获取 jQuery 代码并将其转换为 YUI3 模块),那么这个 jQuery 插件正是您想要做的:https://github.com/mathiasbynens/Placeholder-jQuery-Plugin
我已经在生产环境中使用了它并且它可以工作即使早到 IE6 也很棒:)
If you aren't sold on using YUI exclusively (or are willing to harvest the jQuery code from a plugin and convert it to a YUI3 module) this jQuery plugin does exactly what you are trying to do: https://github.com/mathiasbynens/Placeholder-jQuery-Plugin
I've used it in a production environment and it works great even as far back as IE6 :)