按钮工具提示的数据标题没有更新
data-title not getting updated on button tooltip
我有一个按钮,它的工具提示在启用/禁用时更新。但事实并非如此。这是js和html的绑定。当我使用init时,它不会,但当我使用update时,它会,但然后clickHandlers被调用多次。我正在使用knockout和bootstrap。
<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;
}
});
}
};
您应该设置title
属性,而不是data-title
相关文章:
- 如何从相应的控制器动态更新标题和描述
- 如何在UIWebView中检测AJAX何时更新标题
- 根据复选框值更新第一个标题列
- UI网格AngularJS-如何更新UI网格中的列标题
- 具有动态更新的实时标题 (AJAX+jQuery)
- 通过响应按钮单击更改表标题,其中行使用 JSTL for 循环更新
- Highcharts-如何正确更新VUMeter的系列[0]数据和yAxis标题
- 获取更新的 iFrame 的标题
- 使用 jQuery 更新对话框标题
- ExtJS 6 网格无法正确更新/刷新列标题
- 动态更新 url/html 标题时,如何获得类似 facebook 的按钮来注册更改?(不是 fb:like 中的 hr
- 如何防止数据表更新列标题文本
- SharePoint 2010 - Javascript 根据标题更新列表项值
- 如何检查表中的新内容,然后更新浏览器选项卡标题
- 检查未查看的帖子并更新标题
- 导出时更新的yAxis标题丢失
- 如何在angularjs中更新SPA的标题
- 使用clipboard.js更新悬停时的标题属性
- 代码不工作(请更新标题,当你知道你在问什么)
- Fancybox2加载后更新标题