gpt4 book ai didi

javascript - 使用 Javascript-Header 问题更改属性

转载 作者:行者123 更新时间:2023-11-28 18:35:08 25 4
gpt4 key购买 nike

由于我对 <h2> 做了一些改动,以下 HTML 在我的网站上显示了一种奇特的字体

<section id="content">
<article>
<h2 id="titletext">Welcome to <span>Pomona High School!</span></h2>
<p id="infotext" style="width: 773px; height: 28px;" >Welcome to the new Pomona High School site! Please give us feedback!</p>
<br />
</article>
</section>​

这在站点中显示得很好。

Fancy Header 2 Font

当用户现在转到任务栏并选择其中一个子菜单项时,<h2>文本将更改为指定的字符串值。我进入 Javascript 编辑器并生成了以下内容。

window.onhashchange = function() { //when the hash changes (the '#' part)
var loc = window.location + ""; //get the current location (from the address bar)
var curHash = loc.substr(loc.lastIndexOf("#")); //get what's after the '#'
if (curHash == "#mission") { //else if it's #mission
document.getElementById('titletext').innerHTML = 'Mission Statement';
}

else {
document.getElementById('titletext').innerHTML = 'Welcome to Pomona High School';

}
};​

将其中一个菜单项链接到#mission,我成功地更改了文本。但是字体改成了默认的<h2>字体。

我需要有关如何将我的自定义字体添加到 Javascript 字符串中的帮助。提前致谢!

<h2> 的 CSS 样式表:

h2 {
font-size: 30px;
line-height: 1.2em;
font-weight: normal;
color: #212222;
margin-bottom: 22px;
}

h2 span {
color: #8a8a8a;
}

这是两个自定义字体文件(太大而无法复制和粘贴到 Stack Overflow):-

最佳答案

你的代码实际上是在替换

Welcome to <span>Pomona High School!</span>

Welcome to Pomona High School!

注意,没有元素。只需用 span 标签设置它,就可以了。

关于javascript - 使用 Javascript-Header 问题更改属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12999314/

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