尝试将内联javascript部分转换为函数的其余部分。
html
<li><a href="javascript:popupManager.open('http://www.google.com', 'google')">google</a></li>
JS
function PopupManager() {
this.name = "_popupmanager_";
this.windows = {};
};
PopupManager.prototype.open = function(url, name) {
this.windows[name] = window.open(url, name);
this.windows[name].focus();
};
PopupManager.prototype.closeAll = function() {
for (name in this.windows) {
this.closeWindow(name);
}
};
PopupManager.prototype.closeWindow = function(name) {
if (this.windows[name]) {
this.windows[name].close();
delete this.windows[name];
}
};
我试过
HTML
<li><a href="javascript:void(0)" id="popupManager">google</a>
JS
document.getElementById("popupManager").onclick = function () {
var popupManager = new PopupManager();
function PopupManager() {
this.name = "_popupmanager_";
this.windows = {};
};
};
document.getElementById("popupManager").onclick = function () {
var popupManager = new PopupManager();
PopupManager.prototype.open = function(url, option, size, name) {
var url = "http://google.com"
var option = "null, status=no, toolbar=no, menubar=no, titlebar=no,
location=no, scrollbars=no, resizable=no"
var size = 'height=200, width = 814'
this.windows[name] = window.open(url, option, size, name);
this.windows[name].focus();
};
PopupManager.prototype.closeAll = function() {
for (name in this.windows) {
this.closeWindow(name);
}
};
我需要将js与html分开的原因是我正在为href链接设置一长串选项。实际上,我甚至不想要一个href链接。
我正在尝试使用这样的按钮。
<button id="popupManager">google</button>
控制台错误显示“PopupManager未定义”。好吧,我已加入
var popManager = document.getElementById("popupManager");
但我得到同样的错误&amp;我很难过。
我对这里的错误一无所知。