点击哪个h1标签让哪个字体变成红色(使用this)
代码如下
<body>
<h1 onclick="z(this)">张三</h1>
<h1 onclick="q(this)">李四</h1>
<h1 onclick="r(this)">王五</h1>
</body>
<script>
function z(z) {
z.style.color="red";
z.nextSibling.nextSibling.style.color="black"
z.nextSibling.nextSibling.nextSibling.nextSibling.style.color="black"
}
function q(z) {
z.style.color="red";
z.nextSibling.nextSibling.style.color="black"
z.previousSibling.previousSibling.style.color="black"
}
function r(z) {
z.style.color="red";
z.previousSibling.previousSibling.previousSibling.previousSibling.style.color="black"
z.previousSibling.previousSibling.style.color="black"
}
</script>