从特定的 Jquery 数组填充特定的 Div
如何将特定的 JQuery 数组输出到特定的 Div 中。例如,我想将 (phrases[0]) 数组拉入 Div id="div01",将 (phrases[1]) 数组拉入 Div id="div02"。我已经阅读了 JQuery 的所有功能,但找不到这个。
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>');
然后我需要一句话(实际上):
.append makePhrase(phrases[0]) 到 Div id="div01"
但不知道正确的方法。这只是我学习 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( phrases[0] ) to Div id="div01"
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你们很亲近;试试这个:
并证明它在 jsfiddle 上有效: http://jsfiddle.net/SKssF/14
You are very close; Try this:
And proof it works over at jsfiddle: http://jsfiddle.net/SKssF/14