使剑道 UI 下拉列表将“选择控件”的“标题”属性显示为剑道工具提示

Make Kendo UI DropDownList display the Title attribute of Select Control as a kendoTooltip

本文关键字:标题 属性 工具提示 显示 控件 下拉列表 UI 选择 选择控件      更新时间:2023-09-26
为了使

剑道UI DropDownList将title属性显示为kendoTooltip,我需要做什么?

这就是我正在做的:http://jsfiddle.net/EdsonF/qDRv3/1/

<div class="editor-field">
    <select id="Title" name="Title" title="What's your title?">    
    <option value="Mr.">Mr.</option>
    <option value="Mrs.">Mrs.</option>
    <option value="Miss">Miss</option>
</select>
</div>

$(function () {  
var tooltip = $('#Title').kendoTooltip({
        position: "right",
        autoHide: true,
        width: 280,
        animation: {
            open: {
                effects: "slideIn:right",
                duration: 300
            },
            close: {
                effects: "slideIn:right",
                reverse: true,
                duration: 200
            }
        }
    });
$("#Title").kendoDropDownList();
});

问题是title属于原始select,但不属于剑道UI装饰元素。当您在 KendoUI DropDownList 中转换select时,它会创建一些额外的 HTML 元素,但title不会复制到此元素中。

因此,您可以做的是:

// Create DropDownList
var title = $("#Title").kendoDropDownList().data("kendoDropDownList");
// Copy title from the select into the `wrapper` element
title.wrapper.attr("title", $("#Title").attr("title"));
// Now, define the tooltip for this wrapper element
var tooltip = title.wrapper.kendoTooltip({
    position: "right",
    autoHide: true,
    width: 280,
    animation: {
        open: {
            effects: "slideIn:right",
            duration: 300
        },
        close: {
            effects: "slideIn:right",
            reverse: true,
            duration: 200
        }
    }
});

这里的JSFiddle:http://jsfiddle.net/OnaBai/qDRv3/4/

如前所述,您的原始标签被 Kendo UI 包装,并且不会复制"title"属性。通过扩展 DropDownList Kendo.UI 类相对容易修复。以下是我在我的项目(TypeScript)中修复它的方式:

export class DropDownListX extends kendo.ui.DropDownList {
    // Constructor
    constructor(element: Element, options?: kendo.ui.DropDownListOptions) {
        super(element, options);
        // Copy title attribute from element node to its parent (wrapper created by kendo ui)
        $(element).parent().attr("title", $(element).attr("title"));
    }
}
// Create an alias of the prototype (required by kendo.ui.plugin)
DropDownListX.fn = DropDownListX.prototype;
// Deep clone the widget default options
DropDownListX.fn.options = $.extend(true, { }, kendo.ui.DropDownList.fn.options);
// Specify the name of your Kendo UI widget. Used to create the corresponding jQuery plugin.
DropDownListX.fn.options.name = "DropDownListX";
// Create a jQuery plugin.
kendo.ui.plugin(DropDownListX);