我最近做了一个为期5天的训练营,在开始完整的课程之前,我正试图自学更多。我尝试使用和在bootcamp中一样的"mouseover“函数来增加fontSize,但是它显示不能设置fontSize属性。我相信我已经设置了我想要更改的Id,并指定了我想要更改它的程度。
老实说,我对此非常陌生,只是想克服我的第一个Javascript障碍。
function thingHover() {
document.getElementById('Thing').firstChild.style.fontSize = '300%';
}
function thingNormal() {
document.getElementById('Thing').firstChild.style.fontSize = '100%';
}<p id='Thing' onmouseover="thingHover()" onmouseout="thingNormal"> Dunno what I'm gonna do to this text yet, maybe add some JS? </p>
在新兵训练营中,我们将其应用于图标而不是文本。图标似乎悬停在其原始位置上方,略大一些。我不想仅仅因为我的文本代码不起作用就复制粘贴图标代码。
发布于 2019-07-18 19:53:29
下面代码中有拼写错误,请在调用时添加函数括号
function thingHover() {
document.getElementById('Thing').style.fontSize='300%'; //remove firstChild
}
function thingNormal() {
document.getElementById('Thing').style.fontSize='100%'; //remove firstChild
}
</script><p id='Thing' onmouseover="thingHover()" onmouseout="thingNormal()"> Dunno what I'm gonna do to this text yet, maybe add some JS? </p> <!--add space between two attributes and add () on onmouseout-->
发布于 2019-07-18 20:04:44
您没有任何子元素,因此没有第一个子元素:
我做了一些小的编辑,下面是一个有效的代码片段。
function thingHover() {
var thing = document.getElementById('Thing');
thing.firstElementChild.style.fontSize = '300%';
}
function thingNormal() {
var thing = document.getElementById('Thing');
thing.firstElementChild.style.fontSize = '100%';
}<script>
</script>
<div id='Thing'onmouseover="thingHover()" onmouseout="thingNormal()">
<p style='fontSize:100%;'>Dunno what I'm gonna do to this text yet, maybe add some JS?</p>
</div>
https://stackoverflow.com/questions/57093778
复制相似问题