使用脚本按长文本对帖子进行排序 [英] Sort Posts By Long Text with Script

查看:53
本文介绍了使用脚本按长文本对帖子进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个网站在每个帖子中的单词数都不相同.我们有可能使用JavaScript或jQuery根据单词或字符的数量对它们进行排名吗?

A website would not be the same number of words in each post. Is it possible we could rank them based on the number of words or characters with JavaScript or jQuery?

例如,以文本长度创建链接

Eg create links in the text length

0-200 words
201- 400 words
401-600 words

更新:

我使用托管博客.

好吧,我会澄清我的问题.

Well, I will clarify my question.

我希望我可以建立一个链接,以大量的文字引至特定的帖子.

I hope I can make a link that leads to a specific post by the large number of text.

例如: 我有一个页面page1.html (has 150 words)

For example: I have a page page1.html (has 150 words)

我希望我可以链接到该帖子并按类别进行排序.

I hope I can make a link that leads to the post and sorted by category.

此类别基于词频.如果访问者单击链接类别0-200 words,它将显示少于200 words的帖子数量,包括page1.html

This category is based on word frequency. If the visitor clicks the link category 0-200 words, it will display the number of posts that are less than 200 words, including page1.html

我希望这可以解释我的问题.谢谢

I wish this could explain my question. Thank you

推荐答案

很难给出完整的答案,因为我们看不到从中获得字数统计的页面,但是...

It's hard to give a full answer as we can't see the pages where you'd get your word counts from, but...

        <body>

            <p>abc def</p>
            <p>def ghi</p>

        </body>

真的,您可能会使用类似php的内容循环浏览页面列表,然后最后您将获得三个数组,每个数组包含一个包含0-200、201-400和400多个单词的页面列表.

Really you would probably be using something like php to loop through a list of pages and then at the end you will have three arrays, each containing a list of pages with 0-200, 201-400, and 400+ words.

然后,您可以包括每个链接的列表.

Then you can include a list of links to each.

        <script>
            function wordCount(){

                    var e = document.getElementsByTagName('p');

                    var totalWords = 0;
                    for (var i = 0; i < e.length; i++) {

                        var innerTx = e[i].innerHTML;
                        var wordArray = innerTx.split(' ');
                        var thisTotal = wordArray.length;
                        // alert(wordArray.length);
                        totalWords += thisTotal;
                        // totalWords += wordArray.length; 
                    //Do something
                    }//f

                    // var a = 'abc def ghi';
                    // document.write(b.length);


                    // alert(totalWords);
                    if (totalWords > 400 ) {
                        alert('400+');
                    } else if(totalWords > 200){
                        alert('200+');
                    } else {
                        alert('< 200');
                    }

                    alert('Now you need to use this information to add the specific page to an array of pages with the different word counts');
            }

            wordCount();
        </script>

这篇关于使用脚本按长文本对帖子进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆