如何禁用 Bootstrap 上的按钮?
How to disable a button on Bootstrap?
这是我的网站 "Drupal 8" 和 "Drupal Commerce 2" :
https://www.s1biose.com/produit/savon-artisanal-bio-la-cannelle
我想禁用 "Add to Cart" 按钮。所以我在主题的 JS 文件中添加了以下代码:
(function ($) {
$('.commerce-order-item-add-to-cart-form .btn').prop("disabled", true);
})(window.jQuery);
可以,但是有问题
当我更改产品的变体时,按钮激活。为什么?
我想让他残疾。
在此屏幕截图上有效:
enter image description here
在此屏幕截图中,当我更改产品的变体(无需重新加载页面)时,禁用的 class 消失了:
enter image description here
可能是 ajax 更新了它,我会在 Drupal 行为中添加您的代码(行为在 ajax 之后加载):
(function ($) {
'use strict';
Drupal.behaviors.commerceDisableAjax = {
attach: function (context, settings) {
$('.commerce-order-item-add-to-cart-form .btn').prop("disabled", true);
}
};
}(jQuery));
这是我的网站 "Drupal 8" 和 "Drupal Commerce 2" :
https://www.s1biose.com/produit/savon-artisanal-bio-la-cannelle
我想禁用 "Add to Cart" 按钮。所以我在主题的 JS 文件中添加了以下代码:
(function ($) {
$('.commerce-order-item-add-to-cart-form .btn').prop("disabled", true);
})(window.jQuery);
可以,但是有问题
当我更改产品的变体时,按钮激活。为什么?
我想让他残疾。
在此屏幕截图上有效:
enter image description here
在此屏幕截图中,当我更改产品的变体(无需重新加载页面)时,禁用的 class 消失了:
enter image description here
可能是 ajax 更新了它,我会在 Drupal 行为中添加您的代码(行为在 ajax 之后加载):
(function ($) {
'use strict';
Drupal.behaviors.commerceDisableAjax = {
attach: function (context, settings) {
$('.commerce-order-item-add-to-cart-form .btn').prop("disabled", true);
}
};
}(jQuery));