最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

alphabetized - How can I alphabetize within a <textarea>? JavaScript sort()? - Stack Overflow

programmeradmin1浏览0评论

I've seen a few sites now that alphabetize what ever you put in their textarea I was wondering what I would have to do in order to add a button to mine that would produce that? I'm guessing the "JavaScript sort()" function, but I really don't know. All I've seen with that so far is using it to alphabetize arrays. This would be for anything entered, per line, in an open textarea. Any ideas?

Thanks for taking the time to read this.

I've seen a few sites now that alphabetize what ever you put in their textarea I was wondering what I would have to do in order to add a button to mine that would produce that? I'm guessing the "JavaScript sort()" function, but I really don't know. All I've seen with that so far is using it to alphabetize arrays. This would be for anything entered, per line, in an open textarea. Any ideas?

Thanks for taking the time to read this.

Share Improve this question edited Feb 14, 2013 at 4:12 Shurmajee 1,0474 gold badges13 silver badges35 bronze badges asked Feb 14, 2013 at 3:46 user2070685user2070685 795 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 13

split the string into an array, sort it, then join it back together:

var textarea = document.getElementById("theTextareaId"); // or whatever...
textarea.value = textarea.value.split("\n").sort().join("\n");
发布评论

评论列表(0)

  1. 暂无评论