javascript 以document.write写html语句,其中的onclick事件无法触发?

jimoyoushi 2013-09-28 05:45:57
代码如下:
dTree.prototype.node = function(node, nodeId) {

var str = '<div class="dTreeNode">' + this.indent(node, nodeId);

if (this.config.useIcons) {

if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);

if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;

if (this.root.id == node.pid) {

node.icon = this.icon.root;

node.iconOpen = this.icon.root;

}

str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';

}

if (node.url) {
if (!this.callbackfunction)
str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
else
str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="#"';
if (node.title) str += ' title="' + node.title + '"';

if (node.target) str += ' target="' + node.target + '"';

if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';

if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
{
if (this.callbackfunction)
{
//str += ' onclick="displayFunc("'+node.url+'"); return false;"';
str += ' onclick="alert("?????????????"); return false;"';
}
else
str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
}
str += '>';

}

else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)

str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';

str += node.name;

if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';

str += '</div>';

if (node._hc) {

str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';

str += this.addNode(node);

str += '</div>';

}

this.aIndent.pop();

return str;

};


会报错:Uncaught SyntaxError: Unexpected token }
但是没有看见哪里有语法错误呀
...全文
244 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimoyoushi 2013-09-29
  • 打赏
  • 举报
回复
谢谢5楼,刚没刷新,果然是这个问题
jimoyoushi 2013-09-29
  • 打赏
  • 举报
回复
擦 差点吐了,是双引号嵌套的问题,幸好一下想起C里面怎么将“”里面打印出“”来的方法。
str += " onclick='alert(\"?????????????\"); return false;'";
  • 打赏
  • 举报
回复
str += ' onclick="alert(\"?????????????\"); return false;"';
jimoyoushi 2013-09-29
  • 打赏
  • 举报
回复
str += ' onclick="alert("?????????????"); return false;"';
这句话的格式没问题呀,为啥返回后变成了
onclick="alert('?????????????');" return="" false;=""
百思不得其解............
jimoyoushi 2013-09-29
  • 打赏
  • 举报
回复
这个是在html文件调用js文件,行号显示的是html文件里面的 用的chrome 话说用document.write打印这种方式是不是存在问题?
KK3K2005 2013-09-28
  • 打赏
  • 举报
回复
会报错:Uncaught SyntaxError: Unexpected token } 难道没有行号吗 自己仔细点
尘缘udbwcso 2013-09-28
  • 打赏
  • 举报
回复
按提示应该是“}”不匹配 慢慢找,实在找不到就一段一段的给注释掉,哪一段注释掉之后不报错了 就是那一段的问题

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧