0

我在创建表单后使用 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 总是显示,但数量永远不会出现。为什么会这样,我该如何解决?

4

3 回答 3

2

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

('#purchase_quantity_discounts')
    .append('Quanity: </strong> <input type="text" name="quantity"
        placeholder="Enter Quantity" value="1" /'); //> needed before the ')
于 2012-05-21T15:12:41.457 回答
0

From what I see, there are several typos in your example code. Have a look at this jsFiddle that works.

Not sure of that form-parsing utility you're using Utilities.parseForm, but I've recreated the functionality with jQuery

Here's the fiddle: http://jsfiddle.net/pavsaund/Pt2R2/2/

于 2012-05-22T06:44:50.433 回答
0

我建议将ids 添加到您的输入中并以这种方式获取值。

于 2012-05-21T21:33:37.923 回答