更改属性时出现Javascript头问题

更改属性时出现Javascript头问题,javascript,html,css,Javascript,Html,Css,由于我对 将其中一个菜单项链接到#mission,我成功地更改了文本。但是字体更改为默认的字体 我需要关于如何在Javascript中将自定义字体转换为字符串的帮助。提前谢谢 的CSS样式表: 下面是两个自定义字体文件(太大,无法复制并粘贴到堆栈溢出):- 您的代码实际上正在替换 Welcome to <span>Pomona High School!</span> 注意,没有元素。只需使用span标记进行设置,就可以了。您的代码实际上正在替换 Welcome t

由于我对

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

我需要关于如何在Javascript中将自定义字体转换为字符串的帮助。提前谢谢

的CSS样式表:

下面是两个自定义字体文件(太大,无法复制并粘贴到堆栈溢出):-


您的代码实际上正在替换

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

注意,没有元素。只需使用span标记进行设置,就可以了。

您的代码实际上正在替换

Welcome to <span>Pomona High School!</span>
注意,没有元素。只需将其设置为span标记,就可以了

来源:

以下是MDN对此的看法:

当窗口的哈希值更改时触发hashchange事件(请参见 location.hash)

语法:-

  • window.onhashchange=funcRef
  • window.addEventListener(“hashchange”,funcRef,false)
我认为传递
function(){…}
是一个函数引用,但是您可以尝试先定义函数,然后传递一个命名引用吗?代码如下:

function hashChange() { //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';

    }
};

window.onhashchange = hashChange;


好吧,我很困惑。一定是有别的事情在发生,因为它对我在


您的代码删除了hash change上的
中的
,而hash change可能会给出样式。所以它应该是:

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 = '<span>Mission Statement</span>';
    }

    else {
        document.getElementById('titletext').innerHTML = 'Welcome to <span>Pomona High School</span>';
    }​
}
if(curHash == "#mission") {
    ...
}

else if {
    ...
}
应该是:

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 = '<span>Mission Statement</span>';
    }

    else {
        document.getElementById('titletext').innerHTML = 'Welcome to <span>Pomona High School</span>';
    }​
}
if(curHash == "#mission") {
    ...
}

else if {
    ...
}
来源:

以下是MDN对此的看法:

当窗口的哈希值更改时触发hashchange事件(请参见 location.hash)

语法:-

  • window.onhashchange=funcRef
  • window.addEventListener(“hashchange”,funcRef,false)
我认为传递
function(){…}
是一个函数引用,但是您可以尝试先定义函数,然后传递一个命名引用吗?代码如下:

function hashChange() { //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';

    }
};

window.onhashchange = hashChange;


好吧,我很困惑。一定是有别的事情在发生,因为它对我在


您的代码删除了hash change上的
中的
,而hash change可能会给出样式。所以它应该是:

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 = '<span>Mission Statement</span>';
    }

    else {
        document.getElementById('titletext').innerHTML = 'Welcome to <span>Pomona High School</span>';
    }​
}
if(curHash == "#mission") {
    ...
}

else if {
    ...
}
应该是:

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 = '<span>Mission Statement</span>';
    }

    else {
        document.getElementById('titletext').innerHTML = 'Welcome to <span>Pomona High School</span>';
    }​
}
if(curHash == "#mission") {
    ...
}

else if {
    ...
}

else if(curHash==“#任务”)
:else不需要?。。A到底发生了什么?可能您只是缺少了
titletext
元素中的
?对不起,我正在修剪一些不必要的代码。顶部实际上有if(curHash=“#home”),但这不是问题的一部分。
else if(curHash=“#mission”)
:else不需要?。。A到底发生了什么?可能您只是缺少了
titletext
元素中的
?对不起,我正在修剪一些不必要的代码。实际上,顶部有if(curHash==“#home”),但这不是问题的一部分。标记实际上用于将字体颜色从黑色更改为白色。欢迎来到Pomona高中将显示自定义字体。您可以在我在页面顶部提供的HTML代码中看到标记的作用。我实际上无法:-)改为尝试:
document.getElementById('titletext')。innerHTML='Welcome to Pomona高中!'好,那么您的问题不在于粘贴在此处的代码。您可能会在代码的其他地方更改一些css。尝试在firebug中检查html/css。该标记实际上用于将字体颜色从黑色更改为白色。欢迎来到Pomona高中将显示自定义字体。您可以在我在页面顶部提供的HTML代码中看到标记的作用。我实际上无法:-)改为尝试:
document.getElementById('titletext')。innerHTML='Welcome to Pomona高中!'好,那么您的问题不在于粘贴在此处的代码。您可能会在代码的其他地方更改一些css。尝试在firebug中检查html/css。代码将文本更改为白色,但仍无法显示自定义字体。当字符串有标记而不是标记时,将显示我的自定义字体,请记住这一点。:)@parion您还可以向我们提供您的CSS吗?您希望看到样式表的哪些部分?@parion与h2元素相关的任何内容或其他相关内容。如果你太懒了,就把所有东西都扔到这里,有人会编辑它。添加了它。真正的代码是js/Humanst521_BT_400.font.js,但文件太大,无法添加堆栈溢出。也没有道理。XD代码将文本更改为白色,但仍不显示自定义字体。当字符串有标记而不是标记时,将显示我的自定义字体,请记住这一点。:)@parion您还可以向我们提供您的CSS吗?您希望看到样式表的哪些部分?@parion与h2元素相关的任何内容或其他相关内容。如果你太懒了,就把所有东西都扔到这里,有人会编辑它。添加了它。真正的代码是js/Humanst521_BT_400.font.js,但文件太大,无法添加堆栈溢出。也没有道理。除息的