Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript .removeAttr(';style';)不';在ipad上似乎没有预期的效果_Javascript_Jquery_Ios_Css_Ipad - Fatal编程技术网

Javascript .removeAttr(';style';)不';在ipad上似乎没有预期的效果

Javascript .removeAttr(';style';)不';在ipad上似乎没有预期的效果,javascript,jquery,ios,css,ipad,Javascript,Jquery,Ios,Css,Ipad,如果你使用.removeAttr('style'),有人知道为什么CSS不会在ipad上更新吗 下面是一个快速示例,演示如何实现精灵切换: CSS nav li a { background: url('../img/sprites.gif'); } nav li a#pizza { background-position: -40px -42px; } nav li a#beer { background-position: -40px -82px; } nav li a#spagetti {

如果你使用
.removeAttr('style')
,有人知道为什么CSS不会在ipad上更新吗

下面是一个快速示例,演示如何实现精灵切换:

CSS

nav li a { background: url('../img/sprites.gif'); }
nav li a#pizza { background-position: -40px -42px; }
nav li a#beer { background-position: -40px -82px; }
nav li a#spagetti { background-position: -40px -122px; }
Javascript

var $arr_nav_elements = $('nav li a');
$('nav li a').on('click', function(event) {
   //works fine on all modern browsers except ipad!
   $arr_nav_elements.removeAttr('style');

   var $arr_bg_pos = $(this).css('backgroundPosition').split(" ");
   //create "active" state on the current button  
   $(this).css('backgroundPosition', '0 '+$arr_bg_pos[1]); 
}
在上面的示例中,我的按钮在第一次单击时将在mysprites.gif中变为“活动”状态,但是在我单击任何不同的按钮后,jQuery的css()应用的内联样式不会在ipad上删除/更新

有什么想法吗?

希望这有助于:

试着这样做:

//replace the $.each(...) block with following
$('nav li a').each(function(){
    $(this).css('name','value'); //here you manually adjust your css styles
});

祝你的项目好运

似乎
.removeAttr('style')
在ipad上有一些问题(可能是所有ios设备)

正如A.Wolff和ᾠῗᵲᄐᶌ 这些替代方案效果良好:

.attr('style','');
.css('backgroundPosition','');

为什么在这里使用each循环?可以是:
$arr_nav_elements.removeAttr('style')
$arr\u nav\u elements.attr('style','')
您确定它适用于所有浏览器吗<代码>ele.removeAttr('style')不应该工作,因为
ele
只是一个本地DOM元素,没有方法removeAttrSorry,我只是从头开始写了这个例子。沃尔夫:是的,谢谢!已删除each()-现在应该是正确的。:)很抱歉,与其更改有问题的代码,不如尝试测试它。也许现在它可以工作了,顺便说一句,我们不再知道您使用的是哪种代码。。。那么,你可以发布你正在使用的确切代码,哪些代码不起作用???