Make Kendo UI DropDownList将Select Control的Title属性显示为kendoTooltip

时间:2013-11-02 20:19:27

标签: javascript jquery kendo-ui kendo-asp.net-mvc kendo-combobox

为了使Kendo 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();
});

2 个答案:

答案 0 :(得分:3)

问题是title属于原始select但不属于Kendo 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/

答案 1 :(得分:2)

如前所述,您的原始标记由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);