我有一些文本在一个网站,我想改变使用javascript,因为我不能改变它任何其他方式。
简言之,该网站的布局如下:
...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>谢谢。
发布于 2014-10-16 18:15:40
查看页面的实际来源,您的页面不包含带有类h1的title元素。
你的实际源代码
这意味着它在页面加载之后的某个点之前不存在。您需要将代码放在生成h1标题元素的代码之后。
发布于 2014-10-16 18:14:07
在jQuery中(如果您可以使用它),您可以使用以下内容
$("#title").text("Something else");发布于 2014-10-16 18:14:18
看起来,您没有得到特定的类来更改html。
试着像我做的那样对待querySelector
JS Fiddle
var targetDiv = document.querySelector('#header > .hero-unit > h1.title')
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.";https://stackoverflow.com/questions/26410678
复制相似问题