安全上下文
此特征只可用于
安全上下文
(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. |
候选推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
shippingoptionchange
event
|
Chrome 61 | Edge 15 |
Firefox
55
注意事项
Disabled
|
IE 不支持 No | Opera 不支持 No | Safari 11.1 | WebView Android 不支持 No | Chrome Android 53 |
Firefox Android
55
注意事项
Disabled
|
Opera Android 不支持 No | Safari iOS 11.3 | Samsung Internet Android 6.0 |
完整支持
不支持
见实现注意事项。
用户必须明确启用此特征。
onshippingoptionchange
event handler property
PaymentRequest