如何在 JavaScript 中使用 zindex [英] How to use zindex in JavaScript

查看:38
本文介绍了如何在 JavaScript 中使用 zindex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

zindex 的语法是什么?

What is the syntax for zindex?

我试过这样

document.getElementById('iframe_div1').style.zIndex =2000;
document.getElementById('iframe_div1').style.z-index =2000;

它不起作用,它甚至没有显示错误.

It is not working, it doesn't even show an error.

这是我的片段.它在 HTML 中运行良好,但我想在 jQuery 或 JavaScript 中设置此 CSS 属性.顶部/位置属性不起作用...

This is my snippet. It is working fine in HTML, but I want to set this CSS property in jQuery or JavaScript. The top/position attributes are not working...

z-index:1200px;顶部:450px;位置:绝对;右:300px;

z-index:1200px; top:450px; position:absolute; right:300px;

document.getElementById('iframe_div1').style.display='block';
$("#iframe_div1").css("z-index", "500");
$("#iframe_div1").css("right", "300");
$("#iframe_div1").css("top", "450");
document.getElementById('iframe_div1').style.position = "absolute";

这个片段并不像我想象的那么完美.我想移动页面的 div 中心,但它只是将我的 div 移动到页面底部.

This snippet is not as perfect as I expect. I want to move my div center of the page, but it just moving my div to the bottom of the page.

推荐答案

前者应该没问题.使用像 Firebug 的检查元素"这样的 DOM 检查器来找出值是否被分配,但没有达到预期的效果.

The former should work all right. Use a DOM inspector like Firebug's "inspect element" to find out whether maybe the value gets assigned, but doesn't have the desired effect.

在 jQuery 中,它会是

In jQuery, it would be

 $("#iframe_div1").css("z-index", "2000");

这篇关于如何在 JavaScript 中使用 zindex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆