我目前正在尝试使用javascript动态添加文本框。我有成分和数量,我希望能够继续添加点击添加成分。
我的Javascript看起来像这样:
$('.recipe-ingredients #addNewIngredient').on('click', function () {
var i = $('.recipe-ingredients .ingredient').size() + 1;
$('<div class="form-group ingredient"><label class="control-label" for="searchinput">Ingredients</label><div><input id="ingredient_' + i + '" name="ingredients[]" type="text" placeholder="Ingredients" class="form-control input-md"></div></div><a href="javascript:void(0)" class="pure-button pure-u-1-6 pure-button-primary" id="addNewIngredient">Add Ingredient</a></div>').appendTo($('.recipe-ingredients .ingredients'));
$('<div class="form-group"><label class="control-label" for="buttondropdown">Quantity</label><div class="input-group"><input id="quantity_' + i + '" name="quantity[]" class="form-control" placeholder="Quantity" type="text"><div class="input-group-btn"><button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Measure<span class="caret"></span></button><ul class="dropdown pull-right"><li><a href="#">Grams</a></li><li><a href="#">Ounces</a></li><li><a href="#">Option three</a></li></ul></div></div>').appendTo($'.recipe-quantities .quantities'));
加载页面时,我收到一个控制台错误,上面写着:
Uncaught SyntaxError: Unexpected string
有人可以告诉我我做错了什么吗?
答案 0 :(得分:1)
.appendTo($'.recipe-quantities .quantities')
也许你的意思是.appendTo($('.recipe-quantities .quantities'))