通过ID更改页脚大小
我正在尝试根据所显示的功能运行一个函数,该函数会更改边距大小。但是,它似乎不起作用吗?
<body onload="changeFooter()">
<script>
const heading = document.getElementById('verify');
const footer = document.getElementById('footer')
function changeFooter () {
if (heading == true){
footer.style.marginTop = "200px"
}
}
也尝试了此
function changeFooter () {
if (heading.match('Verify')){
footer.style.marginTop = "200px"
}
}
</script>
<h1 id="verify" class="verifyheading">Verify Identity</h1>
谢谢
I am trying to run a function that changes the margin-top size according to what is being displayed. However, it doesn't seem to be working?
<body onload="changeFooter()">
<script>
const heading = document.getElementById('verify');
const footer = document.getElementById('footer')
function changeFooter () {
if (heading == true){
footer.style.marginTop = "200px"
}
}
also tried this
function changeFooter () {
if (heading.match('Verify')){
footer.style.marginTop = "200px"
}
}
</script>
<h1 id="verify" class="verifyheading">Verify Identity</h1>
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
document.getElementById
返回元素(如果存在)或null,而不是布尔值(true/false)。您可以简单地做
,如果(标题){...}
作为您的条件。这是基于您的代码的摘要: https://codepen.io/29b6/pen/pen/pen/pen/pen/pen/pen/xwzvqqwx
document.getElementById
returns the element (if it exists) or null, not a boolean (true/false).You can simply do
if(heading) { ... }
as your condition.Here's a snippet based on your code: https://codepen.io/29b6/pen/XWZVqWx
在您的
&lt; h1&gt;
的行代码脚本标签之前,标题
在&gt;
之前将行代码取消:如果还没有定义:Let put line code of
<h1>
before yourscript
tag,heading
will null if not define yet: