使用 jQuery:如何防止子级 (<span>
) 继承父级 (<p>
) 的属性?我已经为此工作和研究了 2 个多小时;没有任何效果。
问题部分:
$("p").not("span").css("cursor", "pointer");
<p>...<span>...</span></p>
完整代码:
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<style>body {font-family:Arial,san-serif;font-size:25pt;}</style>
<body>
<p>Always shown | <span>Show/Hide</span></p>
<p>Always shown | <span>Show/Hide</span></p>
</body>
<script>
//Change pointer to a hand:
$("p").not("span").css("cursor", "pointer");
//Show & Hide by clicking on "Always shown":
function handler(event) {
var target = $(event.target);
if (target.is("p")) {
target.children().toggle();
}
}
$("body").click(handler).find("span").hide();
</script>
最佳答案
为什么不用css?
p{ cursor: pointer; }
p span{ cursor: default; }
关于javascript - jQuery:防止 child 继承 parent 的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29858381/