【发布时间】:2017-09-30 01:26:09
【问题描述】:
我是 javascript 和 jquery 的新手。我需要帮助找出我的代码出了什么问题,因为它在最后的步骤中没有执行“.sort()”和“.join(”、“)...
我希望页面有一个弹出框,用户在其中输入位置(输入存储在数组中)并继续,直到他们输入“完成”,然后页面按字母顺序加载他们的位置列表用逗号排序。我的第一部分没问题(提示和输入文本),但我的页面在输入“完成”后没有加载输入的材料。以下是我的代码:
<div id="outputPlaces"></div>
<script>
$(document).ready(function() {
var favPlaces = [];
var input = prompt("Please enter your favorite place or type done to stop entering places.");
while (input != 'done') {
favPlaces.push(input);
input = prompt("Please enter another favorite place or type done to stop entering places.");
}
favPlaces.sort();
$('#outputPlaces').html = favPlaces.join(", ")
});
</script>
【问题讨论】:
-
$(…).html是一个函数,您需要像这样调用:$('#outputPlaces').html(favPlaces.join(", "))。 -
@Xufox 哎呀,要输入 favPlaces,我现在修好了..
标签: javascript jquery arrays sorting alphabetical