如何在JS中再嵌套一个JS

JavaScript08

如何在JS中再嵌套一个JS,第1张

例:

test.htm

<script src=1.js></script>

1.js

document.write("<script src=2.js></script>")

2.js

document.write(2)

注意,如果把1.js中的document.write("<script src=2.js></script>")

直接写在html文档中是需这样写:

document.write("<scr"+"ipt src=2.js></scr"+"ipt>")

function myWrite(str){ document.write(str+"<br/>") }function myFun(){ function mySum(x,y) { var z=x+yreturn z } var b=mySum(1,6) myWrite(b) }myFun()1.函数嵌套定义只能出现在函数,不能出现在选择语句或循环语句中;2.嵌套定义的函数只能在嵌套的函数中使用;如上 mySum函数只能在myFun函数调用;不能再其他函数中调用,如myWrite函数;也不能再myFun函数的其他顶层全局代码中调用.

通过嵌套iframe 实现嵌套html页面

<script type="text/javascript">

$(function () {

document.getElementById("ifm").src =""//Url地址

$("#ifm").load(function () {

var h = document.body.clientHeight

var w = document.body.clientWidth

document.getElementById("ifm").height = h + "px"

document.getElementById("ifm").width = w + "px"

})

})

</script>

<body style="overflow-y:hiddenoverflow-x:hidden">

<div id="pageone" style="">

<iframe name="ifm" id="ifm" scrolling="yes" style="background-color: transparent" marginwidth="0" marginheight="0" frameborder="0">

</iframe>

</div>

</body>