我有一个按钮,其工具提示在启用/禁用时更新。但它不是。这是绑定js和html。当我使用init然后它没有,但当我使用更新它但它然后clickHandlers被多次调用。我正在使用淘汰赛和自助训练。
<button class="btn btn-primary" type="button"
id="displaySubmitBtn" data-bind="formSave: {text: isFormComplete() ? '' : missingRequiredTooltip, enable: isFormComplete, click: submitEstimateFromDisplay},
text: bundle.submit_button_label, visible: isSubmitVisible"
data-placement="bottom" data-backdrop="true">
</button>
ko.bindingHandlers.formSave = {
init: function (el, valueAccessor) {
var $el = $(el),
saveEnabled = valueAccessor()['enable'],
text = _.isFunction(valueAccessor()['text']) ? valueAccessor()['text']() : valueAccessor()['text'],
placement = _.isString(valueAccessor()['placement']) ? valueAccessor()['placement'] : 'bottom',
container = _.isString(valueAccessor()['container']) ? valueAccessor()['container'] : 'body',
clickHandler = valueAccessor()['click'];
var enabler = function (enabled) {
// not using $el.prop('disabled') on purpose so BS tooltip will show
if (enabled) {
// enable the button
$el.removeClass('disabled');
$el.attr('data-title', undefined).tooltip('destroy');
}
else {
$el.addClass('disabled');
}
$el.attr('data-title', text);
$el.tooltip({
//title: text,
placement: placement,
container: container
});
};
// call enabler to disable/ enable button and assign tooltip
enabler(saveEnabled());
// enabler listens to the computed method on button getting enabled/diabled
saveEnabled.subscribe(enabler);
$el.on("click", function (evt) {
if (!$el.is('.disabled')) {
$el.attr('data-title', undefined).tooltip('destroy');
if(clickHandler) {
clickHandler(evt);
}
}
else {
evt.preventDefault();
return false;
}
});
}
};
答案 0 :(得分:1)
您应该设置title
属性,而不是data-title