如何从普通的旧 html 链接触发事件(我想切换卡片视图)?
如果我在控件部分按 ID 引用链接,则似乎不会触发我尝试过的任何事件(单击、点击)。
谢谢!
如何从普通的旧 html 链接触发事件(我想切换卡片视图)?
如果我在控件部分按 ID 引用链接,则似乎不会触发我尝试过的任何事件(单击、点击)。
谢谢!
呈现链接后,您可以通过以下方式添加事件侦听器:
Ext.get('[link id here]').on('click', function(){...}, this);
更新
如果你想在用户点击超链接后触发一个事件,你可以简单地添加this.fireEvent('[name of event here]');
,但要注意this
这个函数中的关键字含义,这样你就可以正确地添加监听器......这有意义吗?
将点击监听器添加到包含链接的面板。在示例中,标签具有“链接”类。您可以用您自己的类/ID 替换它,就像在 jQuery 中所做的那样。
listeners: {
scope: this,
itemtap: this.onItemtapAction,
click: {
element: 'el',
fn: function (e) {
if (e.getTarget('a.link')) {
// Switch cards here
}
}
}
我使用简单的 Java 脚本向链接添加了一个侦听器。
首先,我为容器组件创建了一个“激活”监听器:
...
listeners: {
activate: function (newActiveItem, container, oldActiveItem, eOpts) {
this.onActivate(newActiveItem, container, oldActiveItem, eOpts);
}
}
...
这是我的功能:
onActivate: function (newActiveItem, mainNavView, oldActiveItem, eOpts) {
var me = this;
document.getElementById('logOutLink').addEventListener("click",
function(){
me.onLogOut();
}, false);
},
onLogOut:function(){
alert('log out');
}