当输入焦点时突出显示表单行
我有以下一段 Mootools 1.11 代码(不可升级,因为这是在 Joomla 中),我想在其中的某个项目获得焦点时突出显示表单行。然而,这不起作用。我需要知道如何访问表单项的父 div。
window.addEvent('domready', function() {
var list = $$('#ChronoContact_lensorder div.formrow');
list.each(function(element) {
var fx = new Fx.Styles(element, {duration:200, wait:false});
element.addEvent('focus', function(){
fx.start({
'background-color': '#e6f0f2',
color: '#FFF'
});
});
element.addEvent('focus', function(){
fx.start({
'background-color': '#FFF',
'color': '#2F9AD0'
});
});
});
});
HTML 是:
<div class="formrow">
<label for="ud">Uncut Diameter:</label>
<input type="text" id="ud" name="ud" />
</div>
谢谢
I have the following piece of Mootools 1.11 code (not upgradable as this is within Joomla), which I want to highlight the form row, when an item within it is focussed. However, this doesn't work. I need to know how to access the parent div of the form item.
window.addEvent('domready', function() {
var list = $('#ChronoContact_lensorder div.formrow');
list.each(function(element) {
var fx = new Fx.Styles(element, {duration:200, wait:false});
element.addEvent('focus', function(){
fx.start({
'background-color': '#e6f0f2',
color: '#FFF'
});
});
element.addEvent('focus', function(){
fx.start({
'background-color': '#FFF',
'color': '#2F9AD0'
});
});
});
});
HTML is:
<div class="formrow">
<label for="ud">Uncut Diameter:</label>
<input type="text" id="ud" name="ud" />
</div>
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能不想查找
,而是使用
var list = $$('#ChronoContact_lensorder 查找实际的
然后在必要时使用div.formrow input');
.getParent()
方法引用父级,如下所示:未经测试的代码。请注意,第二个事件现在是
blur
而不是focus
,否则两个事件将同时触发,并且可能会恢复彼此的效果!Instead of looking for the
<div>
s, you might want to look for the actual<input>
usingvar list = $$('#ChronoContact_lensorder div.formrow input');
Then refer to the parent using the.getParent()
method when necessary, like this:Untested code. Note that the second event is now
blur
instead offocus
, or else both events will fire at the same time and might revert each other's effects!