动态高级教程第一节:更换层次的内容 | |
当你用 <DIV> 设立一个层次以后, 你可以把它放早屏幕上的任何一个地方。 Internet Explorer 4.0:
用 Explorer 很容易实现层次内容的更换。下面的语句就可以让你随意的更换层 document.all.divID.innerHTML = "任何HTML或文字"
这个语句中的 divID 是你想要更换内容的 DIV 的 ID。 另外,你可以用另一种 document.all["divID"].innerHTML = "任何HTML或文字"而第二种方法更方便于我们写通用的网页。 Netscape Navigator 4.0:
用 Netscape 就稍微麻烦点。 每个层次在 Netscape 里本身就是一个document. document.open() document.write("my text here") document.close() 如果要往层次里写东西,要加上层次的 ID document.layers["divID"].document.open() document.layers["divID"].document.write("my text here") document.layers["divID"].document.close() 通用程序 把上面所讨论的合在一起,我们可以写出一个通用的改换内容的子程序 function layerWrite(id,nestref,text) { if (ns4) { var lyr; if (nestref) { lyr = eval('document.'+nestref+'.document.'+id+'.document') else document.layers[id].document lyr.open() lyr.write(text) lyr.close() } else if (ie4) { document.all[id].innerHTML = text } } 在你的网页里用这个子程序就可以更换内容。 layerWrite("mylayer",null,"my text here") 请点 这里 看更换层次内容的例子 我将会利用这个层次内容更换的功能写一个网页扩展的子程序集。 请稍候。 | |
![]() ![]() ![]() ![]() |