fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").offsetParent().css("background-color","red"); }); }); </script> </head> <body> <button>设置背景颜色</button> <div style="border:1px solid black;width:70%;position:absolute;left:10px;top:50px"> <div style="border:1px solid black;margin:50px;background-color:yellow"> <p>点击按钮这一段的设置第一个定位的父元素的背景颜色。</p> </div></div> </body> </html>
运行结果