我用的是slickgrid。一列(第一列)包含一个链接。现在,将鼠标悬停在链接上(jquery中的mouseenter)时,将显示一个jquery ui对话框,其中包含单击该链接时将可见的一些数据。通常,这将防止用户不得不单击链接。
因为用户可以向网格动态添加行,所以我使用on()绑定事件
$("#grid").on({
mouseenter: function () {
//here I get the correct element but have to store it in global var
myNumber = $(this).text();
$( "#dialog-char" ).dialog("open");
},
mouseleave: function () {
$( "#dialog-char" ).dialog( "close" );
}
},
".char-link"
);
我想将myNumber传递给对话框打开功能:
$( "#dialog-char" ).dialog({
resizable: true,
width: 750,
autoOpen: false,
open: function( event, ui ) {
loadChar(myNumber);
}
});
这样就可以了,但是我还是需要全局变量。如何访问open()函数中的链接?event.target
不是链接,而是包含网格的div。其他目标属性都返回未定义。
这有可能吗?
好吧,看起来没有直接的方法。如果要避免使用全局变量,则可以#dialog-char
使用以下data()
方法在打开之前将有关悬停链接的信息绑定到:
$("#grid").on({
mouseenter: function () {
$( "#dialog-char" ).data('myNumber',$(this).text());
$( "#dialog-char" ).dialog("open");
},
mouseleave: function () {
$( "#dialog-char" ).dialog( "close" );
}
},
".char-link"
);
$( "#dialog-char" ).dialog({
resizable: true,
width: 750,
autoOpen: false,
open: function( event, ui ) {
myNumber= $(this).data('myNumber');
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句