安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

For payment requests that request shipping information, and for which shipping options are offered, the shippingoptionchange event is sent to the PaymentRequest whenever the user chooses a shipping option from the list of available options. The string identifying the currently-selected shipping option can be found in the shippingOption 特性。

冒泡 No
可取消 No
接口 PaymentRequestUpdateEvent
事件处理程序特性 onshippingoptionchange

范例

This code snippet sets up a handler for the shippingoptionchange event. The code recalculates the total charge for the payment based on the selected shipping option. For example, if there are three options (such as "Free ground shipping", "2-day air", and "Next day"), each time the user chooses one of those options, this event handler is called to recalculate the total based on the changed shipping option.

paymentRequest.addEventListener("shippingoptionchange", event => {
  const value = calculateNewTotal(paymentRequest.shippingOption);
  const total = {
    currency: "EUR",
    label: "Total due",
    值,
  };
  event.updateWith({ total });
}, false);
					

After caling a custom function, calculateNewTotal() , to compute the updated total based on the newly-selected shipping option as specified by the shippingOption . The revised total is submitted back to the payment request by calling the event's updateWith() 方法。

You can also create an event handler for shippingoptionchange using its corresponding event handler property, onshippingoptionchange :

paymentRequest.onshippingoptionchange = event => {
  const value = calculateNewTotal(paymentRequest.shippingOption);
  const total = {
    currency: "EUR",
    label: "Total due",
    值,
  };
  event.updateWith({ total });
};
					

规范

规范 状态 注释
支付请求 API
The definition of 'shippingoptionchange' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
shippingoptionchange event Chrome 61 Edge 15 Firefox 55 注意事项 Disabled
55 注意事项 Disabled
Available only in nightly builds.
Disabled ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 不支持 No Safari 11.1 WebView Android 不支持 No Chrome Android 53 Firefox Android 55 注意事项 Disabled
55 注意事项 Disabled
Available only in nightly builds.
Disabled ). To change preferences in Firefox, visit about:config.
Opera Android 不支持 No Safari iOS 11.3 Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: