简体   繁体   English

chrome / safari的jquery问题

[英]jquery issues with chrome/safari

$('#div1').children('div:last').css('border-bottom', '');
$('#div2').focus();

I am using above and it works fine with ie but not with chrome & safari. 我在上面使用,它可以正常工作,例如,但不能与chrome&safari一起使用。 I haven't tried FF. 我没有尝试过FF。

1st line is to find all child divs and remove underline from last one. 第一行是查找所有子div,并删除最后一个下划线。 2nd one is to focus on div2 on some action. 第二个是专注于div2上的某些操作。

What could be wrong in here? 这有什么问题吗? Or do i need any special treatment for those browsers? 还是那些浏览器需要任何特殊待遇?

Focus() is really intended to be used with input elements -- which a DIV is not. Focus()实际上是与输入元素一起使用的,而DIV则不是。 Of course, I have no way of knowing whether you've given one of your inputs the name "div2", but I suspect not. 当然,我无法知道您是否已为输入之一指定了名称“ div2”,但我怀疑没有。 I think what you really want to do is scroll to the position of the div, not give it focus (or you could give focus to an input in the div). 我认为您真正想要做的是滚动到div的位置,而不是使其焦点(或者您可以将焦点赋予div中的输入)。 Thankfully, there's a plugin for that. 值得庆幸的是,有一个插件

As to the border issue, I'd try using 'none' instead of ''. 至于边界问题,我会尝试使用“无”代替“”。

Have you tried this instead? 您尝试过这个吗?

$('#div1').children('div:last').css('border-bottom', 'none');
$('#div2').get(0).focus();

如果要删除底部边框,请尝试将边框宽度设置为0:

$('#div1').children('div:last').css('border-bottom-width', '0');

For the first one try this: 对于第一个,请尝试以下操作:

$('#div1').children('div:last-child').css('border-bottom', '0'); 

for the second one, I agree with tvanfosson. 对于第二个,我同意tvanfosson的观点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM