我有两个JS文件,一个JS文件套用另一个JS文件
JS文件一格式:
document.writeln("<table border=\"0\"width=\"100%\">");
document.writeln(" <tr>");
document.writeln(" <td width=\"100%\"><SCRIPT language=JavaScript src=\"\/top.js\"><\/SCRIPT><\/td>");
document.writeln(" <\/tr>");
document.writeln("<\/table>")
被嵌套的JS文件:top.js
document.writeln("|<a href=\"http://www.123.com/bus/\" target=_self><font color=#ff3300>公交查询</font><\/a>");
document.writeln("|<a href=\"http://www.123.com/tools/calendar.htm\" target=_self>万年历<\/a>");
document.writeln("|<a href=\"http://www.123.com/tools/calculate.htm\" target=_self>计算器<\/a>");
但显示出来的效果,top.js中的内容始终不在JS文件一的表格中,而是显示在表格的下方顺着表格下方排列请问如何解决
JS文件一格式:
document.writeln("<table border=\"0\"width=\"100%\">");
document.writeln(" <tr>");
document.writeln(" <td width=\"100%\"><SCRIPT language=JavaScript src=\"\/top.js\"><\/SCRIPT><\/td>");
document.writeln(" <\/tr>");
document.writeln("<\/table>")
被嵌套的JS文件:top.js
document.writeln("|<a href=\"http://www.123.com/bus/\" target=_self><font color=#ff3300>公交查询</font><\/a>");
document.writeln("|<a href=\"http://www.123.com/tools/calendar.htm\" target=_self>万年历<\/a>");
document.writeln("|<a href=\"http://www.123.com/tools/calculate.htm\" target=_self>计算器<\/a>");
但显示出来的效果,top.js中的内容始终不在JS文件一的表格中,而是显示在表格的下方顺着表格下方排列请问如何解决
document.writeln("<table border=\"0\" width=\"100%\">");
document.writeln(" <tr>");
document.writeln(" <td width=\"100%\"><div id=\"Here\"><SCRIPT language=JavaScript src=\"\/top.js\"><\/SCRIPT><\/div><\/td>");
document.writeln(" <\/tr>");
document.writeln("<\/table>")注意在TABLE的TD中, 增加了一个DIV,ID是"Here", 用来定位你要用JS动态添加的内容.被调用者JS2
var Target = document.getElementById("Here");
if (Target)
{
Target.innerHTML = "|<a href=\"http://www.123.com/bus/\" target=_self><font color=#ff3300>公交查询</font><\/a>";
Target.innerHTML += "<br>|<a href=\"http://www.123.com/tools/calendar.htm\" target=_self>万年历<\/a>";
Target.innerHTML += "<br>|<a href=\"http://www.123.com/tools/calculate.htm\" target=_self>计算器<\/a>";
}
如果被调用者JS2是第三方的,无法修改呢?
不可否认这个是一个解决方法,应该有效,望Anonymouser兄弟能帮我解决被调用者是第三方的js。实在解决不了的话也结贴给分了!
当你document.write(....)中包含JS时候
这个JS是异步加载 这个时候将继续执行后面的document.write(...)
然后上面哪个JS加载好了才开始执行这个JS中的代码
因为都是调用document.write的文档流 这样就产生了输出结果的先后次序个人认为解决办法是把2段JS合在一个文件里
我想了下可以这样document.write重新分段封装<script>快中 这样都是同级块应该就能保证执行顺序了
<script>
document.writeln("<table border=\"0\" width=\"100%\">");
document.writeln(" <tr>");
document.writeln(" <td width=\"100%\"><div id=\"Here\">")
</script>
<SCRIPT language=JavaScript src="top.js"></SCRIPT>
<script>
document.writeln("<\/div><\/td>");
document.writeln(" <\/tr>");
document.writeln("<\/table>")
</script>