继承(inherits)
其父标签(parent element)
的 CSS 属性。
例如,h3
标签jQuery Playground
的父标签是<div class="container-fluid">
,<div class="container-fluid">
的父标签是body
。
jQuery 有一个parent()
方法,可以访问被选取标签的父标签。
下面的代码展示了使用parent()
方法把left-well
标签的父标签背景色设置成蓝色(blue)
的方式:
$("#left-well").parent().css("background-color", "blue")
请把#target1
标签的父标签背景色设置成红色(red)
。
left-well
标签应该有红色的背景。
testString: assert($("#left-well").css("background-color") === 'red' || $("#left-well").css("background-color") === 'rgb(255, 0, 0)' || $("#left-well").css("background-color").toLowerCase() === '#ff0000' || $("#left-well").css("background-color").toLowerCase() === '#f00');
- text: 应该用.parent()
方法修改该标签。
testString: assert(code.match(/\.parent\s*\(\s*\)\s*\.css/g));
- text: 应该在#target1
标签上调用.parent()
方法。
testString: assert(code.match(/\$\s*?\(\s*?(?:'|")\s*?#target1\s*?(?:'|")\s*?\)\s*?\.parent/gi));
- text: 仅用 jQuery 给标签添加类。
testString: assert(code.match(/