【发布时间】:2014-03-28 03:21:50
【问题描述】:
我在条带代码上看到了它,但我没有在表单提交中以这种方式使用它。
https://gist.github.com/briancollins/6365455
使用.get(0)的原因是什么?
var stripeResponseHandler = function(status, response) {
var $form = $('#payment-form');
if (response.error) {
// Show the errors on the form
$form.find('.payment-errors').text(response.error.message);
$form.find('button').prop('disabled', false);
} else {
// token contains id, last4, and card type
var token = response.id;
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
// and re-submit
$form.get(0).submit();
}
【问题讨论】:
-
查看文档:api.jquery.com/get
$form.get(0)与$form[0]相同。它从 jQuery 对象中获取位置0的 DOM 元素。 -
@RocketHazmat 因为这里没有更好(或更多参与)的答案..
标签: jquery