我从4个不同的Kendo下拉菜单中触发相同的javascript函数。我希望能够分辨哪一个下拉列表是触发器。这里只是其中一个事件调用(所有四个都是相同的)和函数。
@(Html.Kendo().DropDownList()
.Name("myDropdownListName")
......
......
.Events(e => e.Change("aJavascriptFunction")))
function aJavascriptFunction() {
alert(name of dropdown list or some other distinguishable thing here )
}
我认为它与this关键字有关,但不知道this关键字是否适用于这种情况。想法。?
答案 0 :(得分:1)
将e
传递给事件处理程序,并使用其currentTarget
属性来确定触发事件的元素。
function aJavascriptFunction(e) {
console.log(e.currentTarget);
}
<强>更新强>:
尝试将事件绑定更改为模板委托类型:
@(Html.Kendo().DropDownList()
.Name("myDropdownListName")
......
......
.Events(e => e
.Change(@<text>
function(e) {
aJavascriptFunction(e);
}
</text>
)))