问题
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