Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.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
获取zindex javascript浏览器_Javascript_Get_Google Chrome_Z Index - Fatal编程技术网

获取zindex javascript浏览器

获取zindex javascript浏览器,javascript,get,google-chrome,z-index,Javascript,Get,Google Chrome,Z Index,有人能告诉我如何在谷歌浏览器中找到一个div的zindex吗 document.getElementById(id).style.zIndex; //does not work 使用jQuery $('#id').css( 'zIndex' ) 使用jQuery $('#id').css( 'zIndex' ) 这是在我的Chrome版本中使用的标准跨浏览器符号。 在继续之前,我会检查以确保JavaScript的每个部分都返回您期望的结果: alert(document.getElemen

有人能告诉我如何在谷歌浏览器中找到一个div的zindex吗

document.getElementById(id).style.zIndex; //does not work
使用jQuery

$('#id').css( 'zIndex' )
使用jQuery

$('#id').css( 'zIndex' )

这是在我的Chrome版本中使用的标准跨浏览器符号。 在继续之前,我会检查以确保JavaScript的每个部分都返回您期望的结果:

alert(document.getElementById(id)); // should return an [object HTMLElement]
alert(document.getElementById(id).style); // should return an [object CSSStyleDeclaration]
alert(document.getElementById(id).style.zIndex); // should return blank (default) or a number
还有,你怎么知道已经定了? 它可以是继承的或自动的。。。(这意味着它没有为该元素显式声明)


另外,请确保在DOM中的元素可用后运行它。

这是一种标准的跨浏览器表示法,在我的Chrome版本中有效。 在继续之前,我会检查以确保JavaScript的每个部分都返回您期望的结果:

alert(document.getElementById(id)); // should return an [object HTMLElement]
alert(document.getElementById(id).style); // should return an [object CSSStyleDeclaration]
alert(document.getElementById(id).style.zIndex); // should return blank (default) or a number
还有,你怎么知道已经定了? 它可以是继承的或自动的。。。(这意味着它没有为该元素显式声明)


另外,请确保在DOM中的元素可用后运行它。

因为CSS部分中提到了z索引,所以您无法通过您提到的代码直接获得它。您可以使用以下示例

function getStyle(el,styleProp)
{
    var x = document.getElementById(el);

    if (window.getComputedStyle)
    {
        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); 
    }  
    else if (x.currentStyle)
    {
        var y = x.currentStyle[styleProp];
    }                     

    return y;
}
传递元素id和样式属性以访问函数

例如:

对于firefox,您必须传递z-index而不是zIndex

var zInd = getStyle ( "normaldiv1" , "z-index" );
 alert ( zInd );

由于在CSS部分中提到了z索引,您将无法通过您提到的代码直接获得它。您可以使用以下示例

function getStyle(el,styleProp)
{
    var x = document.getElementById(el);

    if (window.getComputedStyle)
    {
        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); 
    }  
    else if (x.currentStyle)
    {
        var y = x.currentStyle[styleProp];
    }                     

    return y;
}
传递元素id和样式属性以访问函数

例如:

对于firefox,您必须传递z-index而不是zIndex

var zInd = getStyle ( "normaldiv1" , "z-index" );
 alert ( zInd );
复制复制或警报(getStyle(“normaldiv1”、“z-index”)??或警报(getStyle(“normaldiv1”、“z-index”)??