我从 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 关键字在这种情况下是否有效。想法。?
最佳答案
将 e
传递给事件处理程序,并使用其 currentTarget
属性来确定哪个元素触发了事件。
function aJavascriptFunction(e) {
console.log(e.currentTarget);
}
更新:
尝试将事件绑定(bind)更改为模板委托(delegate)类型:
@(Html.Kendo().DropDownList()
.Name("myDropdownListName")
......
......
.Events(e => e
.Change(@<text>
function(e) {
aJavascriptFunction(e);
}
</text>
)))
关于javascript - 哪个控件触发了该事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44617401/