我在网站上有一些文字,我想改变使用JavaScript,因为我无法改变任何其他方式。如何使用inner html更改网页中的静态文本?
总之,该网站是奠定了喜欢这样:
...some other divs before here, body, head, etc...
<div id="header" class="container-fluid clearfix">
<div class = "hero-unit">
<h1 class="title">Support Center</h1>
...some other divs for other parts of the page...
</div>
</div>
...more divs, footer, etc...
我不需要文字来改变点击或者类似的东西,我只是希望它是负载设置的东西比不同Support Center
但我不确定是否将脚本放在正确的位置或语法错误?
我试过把它放在前后,它似乎不工作。这里是代码:
<script type="text/javascript">
var targetDiv = document.getElementByID("header").getElementsByClassName("hero-unit")[0].getElementsByClassName("title")[0];
targetDiv.innerHTML = "Please use the Knowledge Base to find answers to the most frequently asked questions or you may submit a support ticket which will be sent to your COM email account.";
</script>
谢谢。
在Javascript的情况下,它的:'getElementById'注意小写** d **最后,你应该得到** undefined不是在JavaScript控制台中的函数**(或类似的错误,取决于浏览器) – 2014-10-16 17:49:00
该死的......好吧,我修正了这个问题,然后再次尝试,仍然没有改变文本。我试图在相关的div之前和之后的脚本,没有。这个脚本应该在我的HTML文件中的这些div之前还是之后?在控制台中,如果我把脚本放在后面,我现在得到的错误是“Uncaught TypeError:无法设置未定义的default.asp?deptID = 15028:142(匿名函数)的属性'innerHTML'”,如果我之前放置它,我得到“无法读取属性'getElementsByClassName'为null”。 – 2014-10-16 17:50:59
你确定你在修复@PatrickEvans发现的东西时没有破坏任何东西吗?看到小提琴:http://jsfiddle.net/fseza1ff/ - 它在这个小小的改正后按预期工作。 – 2014-10-16 17:59:46