• 技术文章 >web前端 >js教程

    jquery怎么修改z-index值

    青灯夜游青灯夜游2021-11-16 15:24:43原创601

    jquery修改z-index值的方法:1、用css()方法,语法“$(selector).css("z-index","值")”;2、用attr()方法,语法“$(selector).attr("style","z-index:值")”。

    本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。

    在jquery中,可以利用css()或attr()方法来修改元素的z-index值。

    示例:

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8" />
    		<style type="text/css">
    			img {
    				position: absolute;
    				left: 0px;
    				top: 0px;
    				z-index: -1;
    			}
    		</style>
    		<script src="js/jquery-1.10.2.min.js"></script>
    		<script type="text/javascript">
    			$(document).ready(function() {
    				$("button").click(function() {
    					// $("img").css("z-index","1");
    					$("img").attr("style","z-index:1;");
    				});
    			});
    		</script>
    
    	</head>
    
    	<body>
    		<h1>This is a heading</h1>
    		<img src="img/2.jpg" />
    		<p>由于图像的 z-index 是 -1,因此它在文本的后面出现。</p><br /><br /><br /><br /><br /><br />
    		<button id="but1">改变z-index值,让图片在文字前</button> 
    	</body>
    </html>

    1.gif

    相关教程推荐:jQuery视频教程

    以上就是jquery怎么修改z-index值的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:jquery z-index css() attr()
    上一篇:jquery字符串怎样转数字 下一篇:jquery怎么移除当前class
    php培训_php实战培训【立即报名】-php中文网第20期

    相关文章推荐

    • 【活动】充值PHP中文网VIP即送云服务器• jquery对象和js对象有啥区别• jquery能处理双击、单击事件吗• jquery怎么去掉td里的内容• jquery可以遍历array数组吗• jquery attr()怎么显示隐藏元素
    1/1

    PHP中文网