从特定的Jquery数组填充特定的Div [英] Populate specific Div from particular Jquery array

查看:145
本文介绍了从特定的Jquery数组填充特定的Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将特定的JQuery数组输出到特定的Div。例如,我想将(短语[0])数组拉入Div id =div01,将(短语[1])数组拉入Div id =div02。我已经阅读了JQuery的所有功能,但是找不到这个。

How to output a particular JQuery array into a particular Div. For example I want to pull the (phrases[0]) array into Div id="div01", and the (phrases[1]) array into Div id="div02". I have read up all the functions of JQuery but can't find this.

var phrases = [
['nihao', 'orange', '你 好', 'hello'],
['zaijian', 'red', '你 好', 'goodbye']
];

makePhrase = function(phrase){
var div = $('<div class="word"><span class="pinyin">' +phrase[0]+ '</span><br/><span class="chinese">'     +phrase[2]+ '</span><br/><span class="english">' +phrase[3]+ '</span> </div>');

然后我需要一行来表示(有效):

And then I need a line to say (in effect):


.append makePhrase(短语[0])到Div id =div01

.append makePhrase( phrases[0] ) to Div id="div01"

但不知道正确的方法。这只是我学习JQuery的第二天,所以我会感谢一个拼写出来的答案,然后我可以通过进一步的调查了解更多!我讨厌成为noob,但任何帮助将不胜感激。

but do not know the correct method. This is only my second day of learning JQuery so I would appreciate a spell-it-out answer which then I can learn more from through further investigation! I hate being the noob but any help would be appreciated.

推荐答案

你非常接近;尝试这样:

You are very close; Try this:

var phrases = [
    ['nihao', 'orange', '你 好', 'hello'],
    ['zaijian', 'red', '你 好', 'goodbye']
    ];

makePhrase = function(phrase) {
    var div = '<div class="word"><span class="chinese">Chinese: ' + phrase[0] + '</span><br/><span class="pinyin">Pinyin:' + phrase[2] + '</span><br/><span class="english">English: ' + phrase[3] + '</span> </div>';
    return div;
}

$("#div01").append(makePhrase(phrases[0]));
$("#div02").append(makePhrase(phrases[1]));​

并在jsfiddle上进行证明: http://jsfiddle.net/SKssF/14

And proof it works over at jsfiddle: http://jsfiddle.net/SKssF/14

这篇关于从特定的Jquery数组填充特定的Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆