English 中文(简体)
获取前几篇文章当天报价的脚本?
原标题:Script to acquire quote of the day from previous posts?

我花了四个小时试图在Tumblr博客上写一个“今天的引号”的剧本。我是写javascript的初学者。 所以,你能帮我拿这个标本,告诉我需要修改什么才能使剧本发挥作用吗? 我还能如何将剧本制作的文字格式化?

<script type="text/javascript">
    var now = new Date();
    var todayAtMidn = new Date(now.getFullYear(), now.getMonth(), now.getDate());
    var quoteTag = getElementsByTagName("div")
    for (var i = 3; i < quoteTag.length; i++)`
    var quoteDate = document.getElementsByTagName("div");
    for (var i = 3; i < quoteDate.length; i++) {
        if ((quoteDate[i].getAttribute("class") == "date") && (quoteTag[i].getAttribute("class") == "tag")) {
            if ((todayAtMidn.getTime() == quoteDate.getTime()) && (quoteTag ==  QOT )) {
                document.write("Quote Of the Day:{Quote}")
            } else {
                document.write( Thank God, its a new day! );
            }
        } else {
            document.write( Thank God, its a new day! )
        }
    }
</script>

我试图做的是,从我的一个正常报价文章中获取内容/文本,只要引文上贴有“QOT”标签,并贴在当前日期(今天如此)上。 然后文本/内容将作为“当天的引用”在网站的特别部分上显示。

我的网站是:goodnigeria.tumblr.com。

问题回答

那么,让我们从以下几个方面开始:

  1. 最初

    (function () {
    
    var post=null;
    
  2. 在当前页面上环绕文章 :

    var posts=getPosts();
    var midnight_today=getMidnight();
    
    for(var i=0, l=posts.length; i<l; i++) {
    
  3. 当我们找到第一个贴有 标签并张贴于今天的文章时停止

       var post_time = getPostTime(post[i]);
       if (postHasTag(posts[i],  QOT ) && post_time > midnight_today) {
           post = posts[i];
           break;
       }
    
    }
    
  4. 如果我们找不到文章: 引用"今天没有引用"

    if (post === null) { 
        setQuote("No quote picked for today");
    } else {
    
  5. 以其他方式:将引文置于我们发现的文章文本中

        setQuote(getQuoteFromPost(post));
    }
    
    })();
    

如果定义了所有未定义的功能, 将按您的要求执行 。


由于图象字节页面上的所有文章都包含 " code > post 类,而引号则包含 " code > quote

(function () {
  var quotes = $("div.post.quote");
  if (quotes.length > 0) {
    $( div#header > h8 ).empty().append(
      quotes.first().find("div.content > blockquote").clone()
    );
  }
})();

将每日报价替换为页面上的第一个引号,如果没有第一个引号,则 div#header> h8 的内容仍作为占位符内容。如果这也是为了检查日期,则需要分析 div.post.quate > div.date 的内容并比较日期。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签