我有一个特定的问题。我尝试通过javascript函数创建动态html代码,并将其放入dojo对话框内容中。我的javascript函数是:dojo对话框动态内容2
function doPushButton(doc, id, action, title, imgRef, text, width, style) {
var tabIndex;
if(arguments.length > 8)
tabIndex = arguments[8];
var accessKey;
if(arguments.length > 9)
accessKey = arguments[9];
jt_docWrite('<div class="' + style + '" style="cursor: pointer' + (width > 0 ? ';width:' + width + 'px' : '') + '"', doc);
if(id != null)
jt_docWrite(' id="' + id + '"', doc);
if(tabIndex != null)
jt_docWrite(' tabindex="' + tabIndex + '"', doc);
if(accessKey != null)
jt_docWrite(' accesskey="' + accessKey + '"', doc);
jt_docWrite(' title="' + title + '" onclick="' + action + '">', doc);
if(imgRef != null)
jt_docWriteln('<img class="label_icon right" src="' + imgRef + '"/>', doc);
if(text != null)
jt_docWriteln('<span class="label">' + text + '</span>', doc);
jt_docWriteln('</div>', doc);
}
其中jt_docWrite和jt_docWriteln是JS功能:
function jt_docWrite() {
if (arguments.length == 1) {
document.write(arguments[0]);
}
if (arguments.length == 2) {
arguments[1].write(arguments[0]);
}
}
这doPushButton()函数调用林在道场dialog.create:
require(["dojo/ready", "dojo/parser"], function(ready, parser){
ready(function(){
var dialog = dijit.byId("myDlg");
dojo.create('div', {
innerHTML: "Hello"
}, dialog.containerNode);
var div = dojo.create('div', {}, dialog.containerNode);
dojo.create('div', {
innerHTML: doPushButton(document, "yes", "doConfirm()", "", "../image/accept.gif", Res_yes_title, 0, "push_button")
}, div);
dialog.show();
});
当我使用我的doPushButton()函数之前在我的HTML页面,如<script> doPushButton(document, "yes", "doConfirm()", "", "../image/accept.gif", Res_yes_title, 0, "push_button") </script>
,它的工作很好,但现在我想把它放在dojo对话框中,它不起作用,并且此函数的结果是“undefine”。有人能帮助我什么是错误的?非常感谢。
米罗