我是这个 javascript 和 dijit 的新手。
我的问题:在我的 js 函数中,我正在构建一个 dijit.Dialog,使用已发送到函数的参数。其中一个参数是指向外部 xhtml 文件的 href,该文件仅包含应该在对话框中显示的文本。现在,我想在 containerNode 中添加一个 div,其中包含另一个指向对话框的链接(带有一个应该特定于每个用户的链接)。问题是我可以确保添加的 div 一直存在,直到我到达 dialog.show,之后它就消失了。来自 xhtml 的文本接管。如果我将它放在 domNode 中(如按钮),它会显示在错误的位置。我还尝试了另一种方法,让链接位于外部 href 中(在文件三中),给它一个 id 并尝试以这种方式访问它并对其进行操作。像这样:
document.getElementById("bytlosen").href="www.xxx.se";
但它不起作用。我得到“document.getElementById(...) 为空。
如果有人可以帮助我如何将 div(链接)添加到对话框中,我会非常高兴!如果我没关系
将它放在文件 3 中,并且可以从文件 2 访问它并对其进行操作,
只需在 js 中添加 div(在文件二中),或者
还有其他方法吗?
我有三个文件:
文件一.xhtml(调用文件二):
<li><a href="#" onclick="new Xxxx.contactsDialog(Xxxx.CONTACT_INFO_TITLE, '${request.contextPath}/content/three.xhtml')">Kontakta oss</a></li>
文件二.js:
Xxxx.contactsDialog = function(title, href, cssClass, destroy) {
if (href) {
var options = {
title: title,
href: href
};
if (cssClass)
options["class"] = cssClass;
var dialog = new dijit.Dialog(options);
var div = document.createElement("div");
var bytLosen = document.createElement("a");
bytLosen.appendChild(document.createTextNode("Byt lösenord"));
bytLosen.setAttribute("href", "https://xxxx.xxx.se/xxx/xxx/xxxx=xxxx&TARGET=xxx.xxx.se");
bytLosen.setAttribute("target", "_blank");
div.appendChild(bytLosen);
dialog.containerNode.appendChild(div);
var okButton = document.createElement("button");
okButton.setAttribute("type", "submit");
okButton.setAttribute("style", "margin-top: 10px");
okButton.innerHTML = "Ok";
dojo.addClass(okButton, "button");
dialog.domNode.appendChild(okButton);
dialog.startup();
dialog.show();
dojo.connect(okButton, "onclick", function() {
dialog.hide();
if (destroy) {
dialog.destroy();
}
});
return true;
} else
return false;
};
文件三.html:
<div class="popupHeader">Synpunkter och felanmälan <span style="font-weight: normal">skickas till:</span></div>
<div><a href="mailto:xxxxxx@xx.se">ajourhallning-xxx@xx.se</a></div>
<div class="popupHeader">Länkar <span style="font-weight: normal">(till xxxx's externa hemsida)</span></div>
<div><a href="http://www.xxxxxx.se" target="_blank">www.xxxxx.se</a></div>
<div><a href="http://www.xxxxx.se/xxxxx" target="_blank">www.xxxx.se/xxx</a></div>
<div class="popupHeader">Byt lösenord</div>