简体   繁体   English

一个JavaScript应用,可返回预定义单词库中输入的单词+单词

[英]a javascript app that return inputted word + words from a predefined word bank

I am trying to make an app that returns inputted word + words from a predefined word bank I have already made an input field and an output iframe and word bank 我正在尝试制作一个可返回预定义单词库中输入的单词和单词的应用程序,我已经创建了一个输入字段以及一个输出iframe和单词库

var bank =["Apples","Banana","Oranges","Grapes","Strawberry"] 

and a function to output 和一个输出功能

$("form").submit(function (e){
        e.preventDefault();
      var output = $(".output").contents().find("html").html($("#input").val());
});

but don't know how to add words to it 但不知道如何添加单词

example: 例:
User input: Delicious 用户输入:美味

App Returns: 应用退货:

Apples Delicious 苹果美味
Banana Delicious 香蕉美味
Oranges Delicious 橘子美味
Grapes Delicious 葡萄美味
Strawberry Delicious 草莓美味

my javascript and jquery skills aren't that great I just learned them about a month ago so help and thanks 我的javascript和jquery技能不是很好,我大约一个月前才了解它们,所以请帮忙并感谢

You can use Array function called map() 您可以使用名为map()的数组函数

var input = 'Delicious';

var delicious = bank.map(function(item) {
  return item + ' ' + input;
});

console.log(delicious);

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

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