[英]jQuery eq not working in mobile safari
I have the following js: 我有以下js:
$('.overlayWrap').on('click', '.overlaySwitch', function(event) {
var $this = $(this),
$overlayRegisterWrap = $('.overlayRegisterWrap li'),
type = $(this).data('go');
event.preventDefault();
$overlayRegisterWrap.hide();
$overlayRegisterWrap.eq(type).show();
});
It works in firefox, chrome and safari but as soon as I try it on mobile it hides all the li's but then does not show the proper li. 它可以在Firefox,Chrome和Safari浏览器中使用,但是一旦我在移动设备上尝试,它就会隐藏所有li,但不会显示适当的li。 If I console log out
$overlayRegisterWrap.eq(type)
it finds the right li but does not display it. 如果我控制台注销
$overlayRegisterWrap.eq(type)
它将找到正确的li,但不会显示它。 I am completely lost. 我完全迷路了。 Anyone have any ideas?
有人有想法么?
EDIT Here is the basic html structure: 编辑这是基本的html结构:
<div id="Overlay" style="" class="overlayWrap" focus="">
<ul class="overlayRegisterWrap">
<li style="display: none;">
//some crazy code
<a class="overlaySwitch" data-go="1">Login</a>
</li>
<li style="display: none;">
//some crazy code
<a class="overlaySwitch" data-go="2">Register</a>
</li>
<li style="display: none;">
//some crazy code
<a class="overlaySwitch" data-go="3">Next</a>
</li>
<li style="display: none;">
//some crazy code
<a class="overlaySwitch" data-go="1">Forgot</a>
</li>
<li style="display: none;">
//some crazy code
<a class="overlaySwitch" data-go="2">Register</a>
</li>
</ul>
</div>
The problem is that you pass a string to jQuery.fn.eq
, but it only accepts numbers. 问题是您将字符串传递给
jQuery.fn.eq
,但它仅接受数字。 You've to "convert" the data-value to an integer. 您必须将数据值“转换”为整数。 In your case the following should do the trick:
在您的情况下,以下方法可以解决问题:
$('.overlayWrap').on('click', '.overlaySwitch', function(event) {
var $this = $(this),
$overlayRegisterWrap = $('.overlayRegisterWrap li'),
type = $(this).data('go') << 0; // We you the bitwise operatir to parse the data-string to an integer
event.preventDefault();
$overlayRegisterWrap.hide();
$overlayRegisterWrap.eq(type).show();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.