简体   繁体   English

我的编码有什么问题?

[英]Whats wrong with my coding?

So on a site they have a "level" where I need to take a lot of words put them in alphabetical order and then paste it in the answer box and then hit submit and all doing this in five seconds? 因此,在一个网站上,他们有一个“等级”,我需要把很多单词按字母顺序排列,然后将其粘贴在答案框中,然后单击“提交”,然后在五秒钟内完成所有这些操作? I am using the console to execute the code which is as follows: 我正在使用控制台执行以下代码:

var id = document.getElementsByTagName("textarea")[0].innerHTML;
id = id.sort();    
id = id.join(",");
document.getElementsByName("answer")[0].innerHTML = id;

can someone tell me why it doesnt work though? 有人可以告诉我为什么它不起作用吗? I get the 我得到了

/* Exception: TypeError: id.sort is not a function @Scratchpad/1:11:6 */

Can anyone tell me whats wrong? 谁能告诉我怎么了? Thanks in advance! 提前致谢!

It is because id is a string, not an array. 这是因为id是一个字符串,而不是数组。 You probably want to have a line like: 您可能希望有这样的一行:

id = id.split(" ") //whatever the separator is

above the id.sort() line. id.sort()行上方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM