admin管理员组文章数量:1304095
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 badges1 Answer
Reset to default 13split
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");
本文标签: alphabetizedHow can I alphabetize within a lttextareagt JavaScript sort()Stack Overflow
版权声明:本文标题:alphabetized - How can I alphabetize within a <textarea>? JavaScript sort()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741782778a2397406.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论