gpt4 book ai didi

javascript - 有条件地改变 fontFamily

转载 作者:行者123 更新时间:2023-11-30 07:42:29 26 4
gpt4 key购买 nike

我希望每 1 秒后连续更改段落的字体系列。这是我的非工作代码...

<!DOCTYPE html>
<html>
<head>
<script src = "jquery.js"> </script>
<script>

$(document).ready(function() {

var idee = document.getElementById('p1');

changeFont();
});

function changeFont()
{
if(idee.style.fontFamily == 'times')
{
idee.style.fontFamily = 'courier';
}
else if(idee.style.fontFamily == 'courier')
{
idee.style.fontFamily = 'times';
}

setTimeout(changeFont, 1000);

}
</script>
</head>

<body>
<p id="p1">This is some text.</p>
</body>

</html>

所以..我做错了什么?如何有条件地改变字体?

最佳答案

这段代码工作正常..

<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
function changeFont()
{
var idee = document.getElementById("p1").style.fontFamily;

if( idee == 'times')
{
document.getElementById("p1").style.fontFamily = 'courier';
}
else if(idee == 'courier')
{
document.getElementById("p1").style.fontFamily = 'times';
}

var int=setTimeout(function(){changeFont();},1000);

}
</script>
</head>

<body onload=" changeFont();">
<p id="p1" style="font-family: times;">This is some text.</p>
</body>

</html>

关于javascript - 有条件地改变 fontFamily,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13757011/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com