我正在尝试动态创建弹出窗口,而不是每个弹出窗口都有相同的ID。问题是,当页面加载时,您选择其ID的第一个弹出窗口将成为下一个窗口的ID。我不知道如何在没有这种情况下有效地编码它。
我的代码是:
// Display relative pop-ups to which link is clicked containing information about the field.
Y.delegate('click', function openPopUpInfo(e) {
var panel,
link = e.target.get('id'),
content = Y.one('#' + link + 'Info');
content.setStyle('display', 'block');
panel = new Y.Panel({
id: 'popUpPanel',
centered: true,
modal: true,
visible: false,
constrain: true,
render: true,
zIndex: 100,
bodyContent: content,
width: 350,
height: 250,
close: true,
plugins: [Y.Plugin.WidgetAnim, Y.Plugin.OverlayKeepaligned],
buttons: [{
value: '',
section: Y.WidgetStdMod.HEADER,
action: function (e) {
e.halt();
panel.hide();
}
}]
});
panel.show();
}, '#interestfreetab', '.infoLink');
答案 0 :(得分:1)
只是一个简单的计数器??
var count = 0;
//existing code
id: 'popUpPanel' + count
//existing code
count++;
答案 1 :(得分:0)
最初设置一个全局变量,如
numberOfPopUps=0;
然后,当你创建一个新的面板时,当声明id时,改变
panel = new Y.Panel({ id: 'popUpPanel',
到
panel = new Y.Panel({ id: 'popUpPanel'+numberOfPopups,
然后在声明增量之后
numberOfPopUps++;