0

我正在尝试为相关结果编写文本,但我希望每个页面的文本都不同,我认为可以使用 document.write 来完成,但我不确定具体的操作方式。我正在使用博客,它为每个页面放置相同的代码,所以你可以理解我不能为每个页面使用不同的 JS,应该有一种方法可以在每个不同的页面上为相关结果提供不同的文本。这是测试页面的链接http://bloghutsbeta.blogspot.com/2012/04/testing-slider.html 那里的图片是相关结果。

这是我的 JS

<script type='text/javascript'>
    var defaultnoimage=&quot;http://1.bp.blogspot.com/_u4gySN2ZgqE/SosvnavWq0I/AAAAAAAAArk/yL95WlyTqr0/s400/noimage.png&quot;;
    var maxresults=14;
    var splittercolor=&quot;none&quot;;
    var relatedpoststitle=&quot;Related Results&quot;;
    </script>
4

3 回答 3

0

您可以做的是检查每个页面的标题。我相信每一页都会有一个独特的标题。根据该标题,您可以使用 JS 为该页面编写文本 var pageTitle = document.title;

if(pageTitle == 'testpage')
{
  document.getElementById('myID').text = 'Your text goes here'
}
else
{
  document.getElementById('myID').text = 'Your new text goes here'
}
于 2012-04-26T08:53:14.573 回答
0

好吧,这里有一些技巧:

window.onload = function() { // Wait for the DOM to be loaded
    var t = document.getElementById('posttitle')
    switch ( window.location.pathname ) {
        case '/2012/04/testing-slider.html':
            t.textContent = 'Some title'
            break
        case '/2012/05/some-thing.html':
            t.textContent = 'Some other title'
            break
    }
}
于 2012-04-26T10:06:03.770 回答
-1

你能做的就是让你的代码像这样

<div id="posttitle" style="display: none;">Related Results</div>

然后将此变量添加到您的 JS

var relatedpoststitle = document.getElementById(&quot;posttitle&quot;).innerHTML;

它应该可以帮助你。

于 2012-04-26T08:48:44.447 回答