javascript - JQuery 表单注入(inject)未出现在提交中

标签 javascript jquery html forms

我在使用 JQuery 在创建表单后将输入添加到表单中时遇到问题。初始形式如下所示:

<form class="purchase-product" >
<div id="purchase_quantity_discounts"></div>
<input type="hidden" name="product_id" value="1" id="label" >
<input type"button" name "submitme" id="product-quantity-button"></button>
</form>

以及用于附加的 JQuery

$('#purchase_quantity_discounts').append('Quanity: </strong> <input type="text" name="quantity" placeholder="Enter Quantity" value="1" />');

现在我正在尝试获取数量:

$('#' + purchase_page).on('click', '#product-quantity-button', function() {
  var formData = Utilities.parseForm(".purchase-product");
  var amount = formData.quantity;
  var product_id = formData.product_id;

  alert(amount);
  alert(product_id);

});

因此,product_id 始终显示,但数量永远不会出现。这是为什么?我该如何解决它?

最佳答案

您的追加缺少输入的结束 >,请参阅:

('#purchase_quantity_discounts')
    .append('Quanity: </strong> <input type="text" name="quantity"
        placeholder="Enter Quantity" value="1" /'); //> needed before the ')

关于javascript - JQuery 表单注入(inject)未出现在提交中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10687890/

相关文章:

Javascript/JQuery 仅在页面焦点上执行 Javascript

javascript - 如何逐个执行 Node js 函数,并在字符串数组中使用它们的名称动态列出

javascript - 如何处理 HTMLElement.Click() 静默失败

python - 如何使用lxml获取url

jQuery 标签问题

javascript - 通过 JQuery 制作 POST API 时显示负载微调器

javascript - 在 IE 中的输入文本字段中按下 Enter 键时按钮 OnClick 触发

jquery - 如何使用 jQuery 递归解析子项

jquery - 响应式肖像图像,如何做和不该做的?

javascript - Angular Ui-Bootstrap 在页面加载时折叠闪烁