javascripot 请教 一个函数的问题

来源:百度知道 编辑:UC知道 时间:2024/05/07 08:49:43
请先看看原代码(一个函数 )

function contextMenu()
{
this.items = new Array();
this.addItem = function (item)
{
this.items[this.items.length] = item;
}
this.show = function (oDoc)
{
var strShow = "";
var i;
strShow = "<div id=\"rightmenu\" style=\"BACKGROUND-COLOR: #ffffff; BORDER: #000000 1px solid; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: hidden; Z-INDEX: 10\">";
strShow += "<table border=\"0\" height=\"";
strShow += this.items.length * 20;
strShow += "\" cellpadding=\"0\" cellspacing=\"0\">";
strShow += "<tr height=\"3\"><td bgcolor=\"#d0d0ce\" width=\"2\"></td><td>";
strShow += "<table border=\"0\" width=\"100%

看这段代码可以得知,show函数就是把html字符串写入到oDoc中。
而this.items[i].show(oDoc);
说明应该还有一个类,与this.show = function (oDoc)类似:
var Item={};
Item=
{
show:function(oDoc)
{
var str = "<table><tr><td>1</td></tr></table>"; // 每个菜单项的html内容
oDoc.write(str);
}
}

oDoc应该是contextMenu出来的新窗口。