how do I get the source (sende)r element of a kendoui widget

淺唱寂寞╮ 提交于 2019-12-10 17:17:24

问题


How does one get the caller (sender) of the kendoui datepicker widget? Or any widget for that matter.

<input id="datepicker1" class="datepicker" value="10/10/2011" />

$(document).ready(function () {
    // ready
    $(".datepicker").kendoDatePicker({
        change: onchange
    });
});

function onchange(e) {
    $(this).hide();
}

Here is a fiddle: http://jsfiddle.net/bryanb/zz48F/


回答1:


The sender is available as this.element. It will be a jQuery object:

$(function () {
    function onchange(e) {
        alert(this.element.prop("id"));
    }

    $(".datepicker").kendoDatePicker({
        change: onchange
    });
});

http://jsfiddle.net/zz48F/3/




回答2:


If you are using kendo button:

You can get the sender in the onclick event of the button using the following :

clickSelector(e) {

        alert("button " + e.sender.element.prop("id"));
    }

and you call clickSelector from the on click event of the button(s)

for example if you have the buttons:

<button id="btnStudentAccounts"  type="button" class="k-button">Student Accounts</button>
<button id="btnFaculty"  type="button" class="k-button">Faculty</button>

And the code:

  that = this;
  $("#btnStudentAccounts").kendoButton({
            enable: true,
            click: function (e) {
                that.clickSelector(e);
            }
        });


$("#btnFaculty").kendoButton({
        enable: true,
        click: function (e) {
               that.clickSelector(e);
            }
        });

if you click over btnFaculty you get:

button btnFaculty



来源:https://stackoverflow.com/questions/14223836/how-do-i-get-the-source-sender-element-of-a-kendoui-widget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!