Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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 除IE外,所有broswer均适用*_Javascript_Jquery_Internet Explorer 8 - Fatal编程技术网

Javascript 除IE外,所有broswer均适用*

Javascript 除IE外,所有broswer均适用*,javascript,jquery,internet-explorer-8,Javascript,Jquery,Internet Explorer 8,我试图解决这个问题,但没有成功。。IE8中存在问题。。它一直在说JSObject是预期的,但似乎无法解决问题所在,因为它在其他任何地方都可以正常工作 jQuery(document).ready(function($) { console.log('here'); // Profile Selector // Get all the big profile elements listed above. // Transform the result of `getElementsByTagNa

我试图解决这个问题,但没有成功。。IE8中存在问题。。它一直在说JSObject是预期的,但似乎无法解决问题所在,因为它在其他任何地方都可以正常工作

jQuery(document).ready(function($) {
console.log('here');
// Profile Selector

// Get all the big profile elements listed above.
// Transform the result of `getElementsByTagName` from a NodeList
// to an Array. Just good practice, really.

var profileWrapper = document.getElementById('profileWrapper');

var bigElements = Array.prototype.slice.call(
    profileWrapper.getElementsByTagName('div')
);

// Find an element in the `bigElements` array above that
// has a className that contains the `id` argument.
function selectBigElement( id ) {

    // loop thru all the elements in `bigElements`, and...
    for( var i = 0; i < bigElements.length; ++i ) {

        // ... if the current element's className contains the
        // query string argument (`id`), then show it...
        if( ~bigElements[i].className.indexOf( id ) ) {
            bigElements[i].style.display = 'block';
        }

        // ... Otherwise, hide it.
        else {
            bigElements[i].style.display = 'none';
        }
    }

};

$('.mini_profile').mouseover(function(event) {
    selectBigElement(this.id);
});

selectBigElement( 179 );
});
jQuery(文档).ready(函数($){
console.log('here');
//轮廓选择器
//获取上面列出的所有大型概要文件元素。
//从节点列表转换'getElementsByTagName'的结果
//到一个阵列。只是很好的练习,真的。
var profileWrapper=document.getElementById('profileWrapper');
var bigfelements=Array.prototype.slice.call(
profileWrapper.getElementsByTagName('div'))
);
//在其上方的“bigElements”数组中查找一个元素
//具有包含'id'参数的类名。
函数selectBigElement(id){
//循环遍历“bigElements”中的所有元素,然后。。。
对于(变量i=0;i
通过查看您的代码,您正在使用一些不受支持的方法:

Array.prototype.slice.call(profileWrapper.getElementsByTagName('div'));
这将尝试将
节点列表
转换为
数组
。这在IE8中不受支持,因为它不支持节点列表作为主机对象

对于常规的
For
循环,您不需要这样做,因为您可以像数组一样在节点列表上循环(不包括
Array.prototype.forEach()
),只需删除
Array.prototype.slice.call()
方法并坚持:

var bigElements = profileWrapper.getElementsByTagName('div');

但是,您正在尝试使用
indexOf
,这是ECMAScript 5,也是一种
Array.prototype
方法。要获得IE8支持,您需要多填充这两个实现或编写一些包装函数以获得相同的结果。

Remove
console.log('here')然后重试
console
仅在console窗口打开时可用。为什么混合使用vanilla js和jquery?IE8是否附带indexOf函数?@cstruter IE8支持
String.prototype.indexOf()
方法,但不支持
Array.prototype.indexOf(),它完成了所有令人讨厌的工作,公开了一个在所有浏览器上都能一致工作的API,这样你就不用担心它了,然后你使用了一些IE8不支持的基本DOM。如果要使用jQuery,请使用它提供的一切。