省略keydown input : function(event) {
和}
给我沿着 “While building the application: client/client.js:33:11: Unexpected token (
” 的线,基本上是起点的错误。我想知道为什么我一开始就需要javascript函数。不要得到错误。这是一个问题,尤其是因为我不希望点击功能在每次按下按键时都运行。无论如何,要弄清楚如何在这里使用jQuery而不是javascript或者更改keydown输入是非常好的。使用jQuery与流星捐赠错误
Template.create_poll.events = {
'keydown input' : function(event) {
$("input").keypress(function() {
var active_element = $(this).parent().attr("id");
var last_child = $('ul li:last').attr("id");
var option_number_index = last_child.lastIndexOf("-");
var option_number = last_child.substring(option_number_index+1);
option_number = option_number/1;
//console.log(option_number);
//console.log(last_child);
if (last_child == active_element) {
console.log(active_element);
option_number += 1;
console.log(option_number);
$('ul').append('<li id="poll-choice-' + option_number + '"><input name="choice" type="text" placeholder="Option ' + option_number + '">');
}
});
$("#poll_create").click(function() {
console.log("Button works");
var choices = new Array();
var counter = 0;
$("ul li input").each(function() {
choices[counter] = $(this).val();
counter++;
});
console.log(choices[1]);
console.log(choices[5]);
});
}
}
您试图混合使用jQuery事件代码和Meteor事件代码。当按照预期使用Meteor时,您应该发现自己使用的是非常少的jQuery代码,因为Meteor正在幕后处理低级jQuery。你应该只是将你的事件实现为''keyup input''并且''点击#poll_create'' – sbking
我还能像'$(this).parent()。attr(“id”);''那样使用jQuery语法吗? – Maaz
流星等值将是'event.currentTarget.parentNode.id'。请注意,这是使用默认的DOM代码。我认为即将发布的新流星模板引擎使用jQuery,所以它可能会变得更像你正在做的事情。我强烈推荐阅读[流星文档](http://docs.meteor.com/)*从上到下*。它解释了很多这些事情。一旦你了解Meteor的工作方式,你应该发现自己几乎不需要任何jQuery语法。流星为你做jQuery的东西。 – sbking